Extension: Json and NetCDF utilities
#include "dg/file/file.h" (includes both Json and NetCDF utilities)
dg::file::NC_Error_Handle Struct Reference

Empty utitlity class that handles return values of netcdf functions and throws NC_Error(status) if( status != NC_NOERR) More...

Public Member Functions

NC_Error_Handle operator= (int err)
 Construct from error code. More...
 
NC_Error_Handle operator() (int err)
 Construct from error code. More...
 

Detailed Description

Empty utitlity class that handles return values of netcdf functions and throws NC_Error(status) if( status != NC_NOERR)

For example

file::NC_Error_Handle err;
int ncid = -1;
try{
err = nc_open( "file.nc", NC_WRITE, &ncid);
//throws if for example "file.nc" does not exist
} catch ( std::exception& e)
{
//log the error and exit
std::cerr << "An error occured opening file.nc !\n"<<e.what()<<std::endl;
exit( EXIT_FAILURE);
}

This allows for a C++ style error handling of netcdf errors in that the program either terminates if the NC_Error is not caught or does something graceful in a try catch statement.

Member Function Documentation

◆ operator()()

NC_Error_Handle dg::file::NC_Error_Handle::operator() ( int  err)
inline

Construct from error code.

throws an NC_Error if err is not a success

Parameters
errnetcdf error code
Returns
Newly instantiated object

◆ operator=()

NC_Error_Handle dg::file::NC_Error_Handle::operator= ( int  err)
inline

Construct from error code.

throws an NC_Error if err is not a success

Parameters
errnetcdf error code
Returns
Newly instantiated object

The documentation for this struct was generated from the following file: