Heidelberg Educational Numerics Library Version 0.27 (from 15 March 2021)
Classes | Macros | Functions
exceptions.hh File Reference

A few common exception classes. More...

#include <string>
#include <sstream>

Go to the source code of this file.

Classes

class  hdnum::Exception
 Base class for Exceptions. More...
 
class  hdnum::IOError
 Default exception class for I/O errors. More...
 
class  hdnum::MathError
 Default exception class for mathematical errors. More...
 
class  hdnum::RangeError
 Default exception class for range errors. More...
 
class  hdnum::NotImplemented
 Default exception for dummy implementations. More...
 
class  hdnum::SystemError
 Default exception class for OS errors. More...
 
class  hdnum::OutOfMemoryError
 Default exception if memory allocation fails. More...
 
class  hdnum::InvalidStateException
 Default exception if a function was called while the object is not in a valid state for that function. More...
 
class  hdnum::ErrorException
 General Error. More...
 

Macros

#define THROWSPEC(E)   #E << ": "
 
#define HDNUM_THROW(E, m)
 
#define HDNUM_ERROR(m)
 

Functions

std::ostream & hdnum::operator<< (std::ostream &stream, const Exception &e)
 

Detailed Description

A few common exception classes.

This file defines a common framework for generating exception subclasses and to throw them in a simple manner. Taken from the DUNE project www.dune-project.org

Macro Definition Documentation

◆ HDNUM_ERROR

#define HDNUM_ERROR ( m)
Value:
do { hdnum::ErrorException th__ex; std::ostringstream th__out; \
th__out << THROWSPEC(hdnum::ErrorException) << m; \
th__ex.message(th__out.str()); \
std::cout << th__ex.what() << std::endl; \
throw th__ex; \
} while (0)
General Error.
Definition exceptions.hh:153
void message(const std::string &message)
store string in internal message buffer
Definition exceptions.hh:43
const std::string & what() const
output internal message buffer
Definition exceptions.hh:48

◆ HDNUM_THROW

#define HDNUM_THROW ( E,
m )
Value:
do { E th__ex; std::ostringstream th__out; \
th__out << THROWSPEC(E) << m; th__ex.message(th__out.str()); throw th__ex; \
} while (0)

Macro to throw an exception

Parameters
Eexception class derived from Dune::Exception
mreason for this exception in ostream-notation

Example:

if (filehandle == 0)
DUNE_THROW(FileError, "Could not open " << filename << " for reading!")

DUNE_THROW automatically adds information about the exception thrown to the text. If DUNE_DEVEL_MODE is defined more detail about the function where the exception happened is included. This mode can be activated via the --enable-dunedevel switch of ./configure