[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: 20010201: VERSION 3.4 C++ NcAtt* NcVar::get_att(NcToken) exit()s



>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