2.3 Get error message corresponding to error status: nc_strerror
The function nc_strerror returns a static reference to an error
message string corresponding to an integer netCDF error status or to a
system error number, presumably returned by a previous call to some
other netCDF function. The list of netCDF error status codes is
available in the appropriate include file for each language binding.
Usage
const char * nc_strerror(int ncerr);
ncerr- An error status that might have been returned from a previous call to
some netCDF function.
Errors
If you provide an invalid integer error status that does not
correspond to any netCDF error message or or to any system error
message (as understood by the system strerror function), nc_strerror
returns a string indicating that there is no such error status.
Example
Here is an example of a simple error handling function that uses
nc_strerror to print the error message corresponding to the netCDF
error status returned from any netCDF function call and then exit:
#include <netcdf.h>
...
void handle_error(int status) {
if (status != NC_NOERR) {
fprintf(stderr, "%s\n", nc_strerror(status));
exit(-1);
}
}