This archive contains answers to questions sent to Unidata support through mid-2025. Note that the archive is no longer being updated. We provide the archive for reference; many of the answers presented here remain technically correct, even if somewhat outdated. For the most up-to-date information on the use of NSF Unidata software and data services, please consult the Software Documentation first.
>To: address@hidden >From: Michael Guzy <address@hidden> >Subject: VERSION 3.4 C++ NcAtt* NcVar::get_att(NcToken) exit()s >Organization: UCAR/Unidata >Keywords: 200102020241.f122fVX04512, C++ error handling, NcError Hi Michael, Sorry it's taken so long to get back to you with an answer. A meeting last week consumed our support time. > In Nov, 2000 I downloaded and built the C++ netCDF. > VERSION 3.4 is the version reported in the distribution. ... > Maybe I did something wrong? > > NcAtt* NcVar::get_att(NcToken) does not behave as advertised: > instead of returning 0 when the attribute does not exist, > the following calls are made. ncopt and ncerr still exist in this code. > > NcAtt::is_valid() > ncattinq() > nc_advise() > exit(). The default error behavior for the C++ interface is NcError::verbose_nonfatal, which means produce an error message on stdout and exit. You can change the error handling by declaring an NcError object, which 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. So to change the error behavior to NcError::silent_nonfatal, just declare an NcError object with that argument, something like: NcError* error_handling = new NcError(NcError::silent_nonfatal); before you call any netCDF member functions. Then any subsequent calls to NcVar::get_att(NcToken) will behave as expected, returning 0 for nonexistent attributes. --Russ