NetCDF-C++  4.3.1-developer
ncException.cpp
1 #include <ncException.h>
2 #include <sstream>
3 #include <netcdf.h>
4 using namespace std;
5 using namespace netCDF;
6 using namespace netCDF::exceptions;
7 
8 
9 // Default object thrown if a netCDF exception is encountered.
10 /*NcException::NcException(const string& complaint,const char* fileName,int lineNumber)
11  : what_msg(NULL)
12  , ec(0)
13 {
14  try{
15  std::ostringstream oss;
16  oss << lineNumber;
17  what_msg = new std::string(complaint+"\nfile: "+fileName+" line:"+oss.str());
18  }catch(...){
19  what_msg = NULL;
20  }
21 }*/
22 
23 NcException::NcException(const char* complaint,const char* fileName,int lineNumber)
24  : what_msg(NULL)
25  , ec(0)
26 {
27  try{
28  std::ostringstream oss;
29  oss << lineNumber;
30  what_msg = new std::string(complaint?complaint:"");
31  what_msg->append("\nfile: ");
32  what_msg->append(fileName);
33  what_msg->append(" line:");
34  what_msg->append(oss.str());
35  }catch(...){
36  what_msg = NULL;
37  }
38 }
39 
40 NcException::NcException(int errorCode, const char* complaint,const char* fileName,int lineNumber)
41  : what_msg(NULL)
42  , ec(errorCode)
43 {
44  try{
45  std::ostringstream oss;
46  oss << lineNumber;
47  what_msg = new std::string(complaint?complaint:"");
48  what_msg->append("\nfile: ");
49  what_msg->append(fileName);
50  what_msg->append(" line:");
51  what_msg->append(oss.str());
52  }catch(...){
53  what_msg = NULL;
54  }
55 }
56 
57 NcException::NcException(const NcException& e) throw()
58  : what_msg(NULL)
59  , ec(e.ec)
60 {
61  try{
62  what_msg = new std::string(*(e.what_msg));
63  }catch(...){
64  what_msg = NULL;
65  }
66 }
67 
68 NcException& NcException::operator=(const NcException& e) throw(){
69  if (this != &e){
70  ec = e.ec;
71  delete what_msg;
72  try{
73  what_msg = new std::string(*(e.what_msg));
74  }catch(...){
75  what_msg = NULL;
76  }
77  }
78  return *this;
79 }
80 
81 NcException::~NcException()throw() {
82  delete what_msg;
83 }
84 
85 
86 const char* NcException::what() const throw()
87 {
88  return what_msg==NULL ? "" : what_msg->c_str();
89 }
90 
91 int NcException::errorCode() const throw() {
92  return ec;
93 }
94 
95 
96 // Thrown if the specified netCDF ID does not refer to an open netCDF dataset.
97 NcBadId::NcBadId(const char* complaint,const char* file,int line) :
98  NcException(NC_EBADID,complaint,file,line) { }
99 
100 
101 // Thrown if too many netcdf files are open.
102 NcNFile::NcNFile(const char* complaint,const char* file,int line) :
103  NcException(NC_ENFILE,complaint,file,line) { }
104 
105 // Thrown if, having set NC_NOCLOBBER, the specified dataset already exists.
106 NcExist::NcExist(const char* complaint,const char* file,int line) :
107  NcException(NC_EEXIST,complaint,file,line) { }
108 
109 // Thrown if not a netCDF id.
110 NcInvalidArg::NcInvalidArg(const char* complaint,const char* file,int line) :
111  NcException(NC_EINVAL,complaint,file,line) { }
112 
113 // Thrown if invalid argument.
114 NcInvalidWrite::NcInvalidWrite(const char* complaint,const char* file,int line) :
115  NcException(NC_EPERM,complaint,file,line) { }
116 
117 // Thrown if operation not allowed in data mode.
118 NcNotInDefineMode::NcNotInDefineMode(const char* complaint,const char* file,int line) :
119  NcException(NC_ENOTINDEFINE,complaint,file,line) { }
120 
121 // Thrown if operation not allowed in defined mode.
122 NcInDefineMode::NcInDefineMode(const char* complaint,const char* file,int line) :
123  NcException(NC_EINDEFINE,complaint,file,line) { }
124 
125 // Index exceeds dimension bound
126 NcInvalidCoords::NcInvalidCoords(const char* complaint,const char* file,int line) :
127  NcException(NC_EINVALCOORDS,complaint,file,line) { }
128 
129 // Thrown if NC_MAX_DIMS is exceeded.
130 NcMaxDims::NcMaxDims(const char* complaint,const char* file,int line) :
131  NcException(NC_EMAXDIMS,complaint,file,line) { }
132 
133 // Thrown if string match to name is in use.
134 NcNameInUse::NcNameInUse(const char* complaint,const char* file,int line) :
135  NcException(NC_ENAMEINUSE,complaint,file,line) { }
136 
137 // Thrown if attribute is not found.
138 NcNotAtt::NcNotAtt(const char* complaint,const char* file,int line) :
139  NcException(NC_ENOTATT,complaint,file,line) { }
140 
141 // Thrown if Nc_MAX_ATTRS is exceeded.
142 NcMaxAtts::NcMaxAtts(const char* complaint,const char* file,int line) :
143  NcException(NC_EMAXATTS,complaint,file,line) { }
144 
145 // Thrown if not a valid netCDF data type.
146 NcBadType::NcBadType(const char* complaint,const char* file,int line) :
147  NcException(NC_EBADTYPE,complaint,file,line) { }
148 
149 // Thrown if an invalid dimension id or name.
150 NcBadDim::NcBadDim(const char* complaint,const char* file,int line) :
151  NcException(NC_EBADDIM,complaint,file,line) { }
152 
153 // Thrown if Nc_UNLIMITED is in the wrong index.
154 NcUnlimPos::NcUnlimPos(const char* complaint,const char* file,int line) :
155  NcException(NC_EUNLIMPOS,complaint,file,line) { }
156 
157 // Thrown if NC_MAX_VARS is exceeded.
158 NcMaxVars::NcMaxVars(const char* complaint,const char* file,int line) :
159  NcException(NC_EMAXVARS,complaint,file,line) { }
160 
161 // Thrown if variable is not found.
162 NcNotVar::NcNotVar(const char* complaint,const char* file,int line) :
163  NcException(NC_ENOTVAR,complaint,file,line) { }
164 
165 // Thrown if the action is prohibited on the NC_GLOBAL varid.
166 NcGlobal::NcGlobal(const char* complaint,const char* file,int line) :
167  NcException(NC_EGLOBAL,complaint,file,line) { }
168 
169 // Thrown if not a netCDF file.
170 NcNotNCF::NcNotNCF(const char* complaint,const char* file,int line) :
171  NcException(NC_ENOTNC,complaint,file,line) { }
172 
173 // Thrown if in FORTRAN, string is too short.
174 NcSts::NcSts(const char* complaint,const char* file,int line) :
175  NcException(NC_ESTS,complaint,file,line) { }
176 
177 // Thrown if NC_MAX_NAME is exceeded.
178 NcMaxName::NcMaxName(const char* complaint,const char* file,int line) :
179  NcException(NC_EMAXNAME,complaint,file,line) { }
180 
181 // Thrown if NC_UNLIMITED size is already in use.
182 NcUnlimit::NcUnlimit(const char* complaint,const char* file,int line) :
183  NcException(NC_EUNLIMIT,complaint,file,line) { }
184 
185 // Thrown if nc_rec op when there are no record vars.
186 NcNoRecVars::NcNoRecVars(const char* complaint,const char* file,int line) :
187  NcException(NC_ENORECVARS,complaint,file,line) { }
188 
189 // Thrown if attempt to convert between text and numbers.
190 NcChar::NcChar(const char* complaint,const char* file,int line) :
191  NcException(NC_ECHAR,complaint,file,line) { }
192 
193 // Thrown if edge+start exceeds dimension bound.
194 NcEdge::NcEdge(const char* complaint,const char* file,int line) :
195  NcException(NC_EEDGE,complaint,file,line) { }
196 
197 // Thrown if illegal stride.
198 NcStride::NcStride(const char* complaint,const char* file,int line) :
199  NcException(NC_ESTRIDE,complaint,file,line) { }
200 
201 // Thrown if attribute or variable name contains illegal characters.
202 NcBadName::NcBadName(const char* complaint,const char* file,int line) :
203  NcException(NC_EBADNAME,complaint,file,line) { }
204 
205 // Thrown if math result not representable.
206 NcRange::NcRange(const char* complaint,const char* file,int line) :
207  NcException(NC_ERANGE,complaint,file,line) { }
208 
209 // Thrown if memory allocation (malloc) failure.
210 NcNoMem::NcNoMem(const char* complaint,const char* file,int line) :
211  NcException(NC_ENOMEM,complaint,file,line) { }
212 
213 // Thrown if one or more variable sizes violate format constraints
214 NcVarSize::NcVarSize(const char* complaint,const char* file,int line) :
215  NcException(NC_EVARSIZE,complaint,file,line) { }
216 
217 // Thrown if invalid dimension size.
218 NcDimSize::NcDimSize(const char* complaint,const char* file,int line) :
219  NcException(NC_EDIMSIZE,complaint,file,line) { }
220 
221 // Thrown if file likely truncated or possibly corrupted.
222 NcTrunc::NcTrunc(const char* complaint,const char* file,int line) :
223  NcException(NC_ETRUNC,complaint,file,line) { }
224 
225 // Thrown if an error was reported by the HDF5 layer.
226 NcHdfErr::NcHdfErr(const char* complaint,const char* file,int line) :
227  NcException(NC_EHDFERR,complaint,file,line) { }
228 
229 // Thrown if cannot read.
230 NcCantRead::NcCantRead(const char* complaint,const char* file,int line) :
231  NcException(NC_ECANTREAD,complaint,file,line) { }
232 
233 // Thrown if cannot write.
234 NcCantWrite::NcCantWrite(const char* complaint,const char* file,int line) :
235  NcException(NC_ECANTWRITE,complaint,file,line) { }
236 
237 // Thrown if cannot create.
238 NcCantCreate::NcCantCreate(const char* complaint,const char* file,int line) :
239  NcException(NC_ECANTCREATE,complaint,file,line) { }
240 
241 // Thrown if file meta.
242 NcFileMeta::NcFileMeta(const char* complaint,const char* file,int line) :
243  NcException(NC_EFILEMETA,complaint,file,line) { }
244 
245 // Thrown if dim meta.
246 NcDimMeta::NcDimMeta(const char* complaint,const char* file,int line) :
247  NcException(NC_EDIMMETA,complaint,file,line) { }
248 
249 // Thrown if attribute meta.
250 NcAttMeta::NcAttMeta(const char* complaint,const char* file,int line) :
251  NcException(NC_EATTMETA,complaint,file,line) { }
252 
253 // Thrown if variable meta.
254 NcVarMeta::NcVarMeta(const char* complaint,const char* file,int line) :
255  NcException(NC_EVARMETA,complaint,file,line) { }
256 
257 // Thrown if no compound.
258 NcNoCompound::NcNoCompound(const char* complaint,const char* file,int line) :
259  NcException(NC_ENOCOMPOUND,complaint,file,line) { }
260 
261 // Thrown if attribute exists.
262 NcAttExists::NcAttExists(const char* complaint,const char* file,int line) :
263  NcException(NC_EATTEXISTS,complaint,file,line) { }
264 
265 // Thrown if attempting netcdf-4 operation on netcdf-3 file.
266 NcNotNc4::NcNotNc4(const char* complaint,const char* file,int line) :
267  NcException(NC_ENOTNC4,complaint,file,line) { }
268 
269 // Thrown if attempting netcdf-4 operation on strict nc3 netcdf-4 file.
270 NcStrictNc3::NcStrictNc3(const char* complaint,const char* file,int line) :
271  NcException(NC_ESTRICTNC3,complaint,file,line) { }
272 
273 // Thrown if bad group id.
274 NcBadGroupId::NcBadGroupId(const char* complaint,const char* file,int line) :
275  NcException(NC_EBADGRPID,complaint,file,line) { }
276 
277 // Thrown if bad type id.
278 NcBadTypeId::NcBadTypeId(const char* complaint,const char* file,int line) :
279  NcException(NC_EBADTYPID,complaint,file,line) { }
280 
281 // Thrown if bad field id.
282 NcBadFieldId::NcBadFieldId(const char* complaint,const char* file,int line) :
283  NcException(NC_EBADFIELD,complaint,file,line) { }
284 
285 // Thrown if cannot find the field id.
286 NcUnknownName::NcUnknownName(const char* complaint,const char* file,int line) :
287  NcException(complaint,file,line) { }
288 
289 // Thrown if cannot find the field id.
290 NcEnoGrp::NcEnoGrp(const char* complaint,const char* file,int line) :
291  NcException(NC_ENOGRP,complaint,file,line) { }
292 
293 // Thrown if cannot find the field id.
294 NcNullGrp::NcNullGrp(const char* complaint,const char* file,int line) :
295  NcException(complaint,file,line) { }
296 
297 // Thrown if cannot find the field id.
298 NcNullDim::NcNullDim(const char* complaint,const char* file,int line) :
299  NcException(complaint,file,line) { }
300 
301 // Thrown if cannot find the field id.
302 NcNullType::NcNullType(const char* complaint,const char* file,int line) :
303  NcException(complaint,file,line) { }
304 
305 // Thrown if an operation to set the deflation, chunking, endianness, fill, compression, or checksum of a NcVar object is issued after a call to NcVar::getVar or NcVar::putVar.
306 NcElateDef::NcElateDef(const char* complaint,const char* file,int line) :
307  NcException(NC_ELATEDEF,complaint,file,line) { }
308 
C++ API for netCDF4.
Definition: ncAtt.h:9
NcChar()
Constructor.
Definition: ncChar.cpp:11
Exception classes.
Definition: ncException.h:15
Base object is thrown if a netCDF exception is encountered.
Definition: ncException.h:24

Return to the Main Unidata NetCDF page.
Generated on Fri Nov 11 2016 15:28:29 for NetCDF-C++. NetCDF is a Unidata library.