Updated over 10 years ago by Knödlseder Jürgen
GammaLib implements error handling using exceptions. The exceptions are implemented by the GException
class. GammaLib distinguishes between logic exceptions and runtime exceptions.
invalid_value
: a value is invalidinvalid_argument
: an argument passed to a method or a function is invalidout_of_range
: a value is outside its valid rangefits_error
: an error occurred in a cfitsio routineunderflow_error
overflow_error
feature_not_implemented
: the requested feature is not yet implemented in GammaLibBelow an example code that illustrates how exceptions should be implemented:
if (num != m_cube.nmaps() ) { std::string msg = "Number of energies in 'ENERGIES' extension" " ("+gammalib::str(num)+") does not match the" " number of maps ("+gammalib::str(m_cube.nmaps())+"" " in the map cube.\n" "The 'ENERGIES' extension table shall provide" " one enegy value for each map in the cube."; throw GException::invalid_value(G_LOAD, msg); }
std::string
. This message is then passed to invalid_value
, invalid_argument
or any of the other standard exceptions. The G_LOAD
macro defines the name of the method that actually throws the exception (and is defined in the header of the .cpp
file):#define G_LOAD "GModelSpatialDiffuseCube::load(std::string&)"
const
declaration and without the parameter name. If more than a single parameter exists, the parameter should be separated by a blank character:#define G_MC "GModelSpatialDiffuseCube::mc(GEnergy&, GTime&, GRan&)"