Previous: Class NcValues, Up: Auxiliary Classes


Class NcError

This class provides control for netCDF error handling. Declaring an NcError object temporarily changes the error-handling behavior for all netCDF classes until the NcError object is destroyed (typically by going out of scope), at which time the previous error-handling behavior is restored.

The C++ interface was developed before exceptions were widely supported, and as a result it still uses return values to indicate error conditions. Member functions that return NcBool yield TRUE on success and FALSE on failure. Member functions that return a pointer value return a NULL pointer on failure.

The definition of “failure” in this context is somewhat ambiguous. For example, inquiring whether a variable has an attribute named “units” requires invoking the NcVar::get_att("units") method, which returns NULL pointer if no such variable attribute exists. Whether this really indicates an error condition depends on the context, because the netCDF interface does not enforce providing a “units” attribute for every variable, although some conventions may have such a requirement. Similarly, asking for the nth variable with NcFile::get_var(n) will return a NULL pointer if n is the number of variables (since variable numbering starts at zero instead of one), but that may be a convenient loop termination condition when iterating through the variables in a file, rather than an error.

Public Member Functions

NcError( Behavior b = verbose_fatal )
The constructor saves the previous error state for restoration when the destructor is invoked, and sets a new specified state. Valid error states are NcError::silent_nonfatal, NcError::verbose_nonfatal, NcError::silent_fatal, or NcError::verbose_fatal, to control whether error messages are output from the underlying library and whether such messages are fatal or nonfatal. Although NcError::verbose_fatal is the default error-handling behavior for backward compatibility with the first version of the C++ interface, explicitly checking method return values and using NcError::silent_nonfatal or NcError::verbose_nonfatal is recommended in cases (as described above) where context determines whether a method “failure” really indicates an error.


~NcError( void )
Destructor, restores previous error state.


int get_err( void )
Returns most recent error, as enumerated in netcdf.h.


const char* get_errmsg( void )
Returns most recent error message string, corresponding to the errors enumerated in netcdf.h.