Previous: Class NcValues, Up: Auxiliary Classes
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.
NcError( Behavior b = verbose_fatal )
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 )
int get_err( void )
const char* get_errmsg( void )