dune-common  2.3.1
Files | Classes | Macros | Functions
Exception handling
Collaboration diagram for Exception handling:

Files

file  exceptions.hh
 A few common exception classes.
 

Classes

class  Dune::Exception
 Base class for Dune-Exceptions. More...
 
struct  Dune::ExceptionHook
 Base class to add a hook to the Dune::Exception. More...
 
class  Dune::IOError
 Default exception class for I/O errors. More...
 
class  Dune::MathError
 Default exception class for mathematical errors. More...
 
class  Dune::RangeError
 Default exception class for range errors. More...
 
class  Dune::NotImplemented
 Default exception for dummy implementations. More...
 
class  Dune::SystemError
 Default exception class for OS errors. More...
 
class  Dune::OutOfMemoryError
 Default exception if memory allocation fails. More...
 
class  Dune::InvalidStateException
 Default exception if a function was called while the object is not in a valid state for that function. More...
 
class  Dune::ParallelError
 Default exception if an error in the parallel communication of the programm occured. More...
 

Macros

#define DUNE_THROW(E, m)
 

Functions

 Dune::Exception::Exception ()
 
void Dune::Exception::message (const std::string &msg)
 store string in internal message buffer More...
 
const std::string & Dune::Exception::what () const
 output internal message buffer More...
 
static void Dune::Exception::registerHook (ExceptionHook *hook)
 add a functor which is called before a Dune::Exception is emitted (see Dune::ExceptionHook) More...
 
static void Dune::Exception::clearHook ()
 remove all hooks More...
 
virtual Dune::ExceptionHook::~ExceptionHook ()
 
virtual void Dune::ExceptionHook::operator() ()=0
 
std::ostream & Dune::operator<< (std::ostream &stream, const Exception &e)
 

Detailed Description

The Dune-exceptions are designed to allow a simple derivation of subclasses and to accept a text written in the '<<' syntax.

Example of usage:

...
class FileNotFoundError : public Dune::IOError {};
...
void fileopen (std::string name) {
std::ifstream file;
file.open(name.c_str());
if (file == 0)
DUNE_THROW(FileNotFoundError, "File " << name << " not found!");
...
file.close();
}
...
int main () {
try {
...
} catch (Dune::IOError &e) {
std::cerr << "I/O error: " << e << std::endl;
return 1;
} catch (Dune::Exception &e) {
std::cerr << "Generic Dune error: " << e << std::endl;
return 2;
}
}
See also
exceptions.hh for detailed info

Macro Definition Documentation

#define DUNE_THROW (   E,
 
)
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

1 #include <dune/common/exceptions.hh>
Parameters
Eexception class derived from Dune::Exception
mreason for this exception in ostream-notation

Example:

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

DUNE_THROW automatically adds information about the exception thrown to the text.

Note
you can add a hook to be called before a Dune::Exception is emitted, e.g. to add additional information to the exception, or to invoke a debugger during parallel debugging. (see Dune::ExceptionHook)

Referenced by Dune::fmatrix_assigner< T, n, m >::append(), Dune::DebugStream< thislevel, dlevel, alevel, activator >::attach(), Dune::BitSetVector< block_size, Allocator >::BitSetVector(), Dune::InterfaceBuilder::buildInterface(), Dune::DebugStream< thislevel, dlevel, alevel, activator >::detach(), Dune::FMatrixHelp::eigenValues(), Dune::FMatrixHelp::eigenValuesLapackCall(), Dune::DynamicMatrixHelp::eigenValuesNonSym(), Dune::FMatrixHelp::eigenValuesNonSym(), Dune::DynamicMatrixHelp::eigenValuesNonsymLapackCall(), Dune::FMatrixHelp::eigenValuesNonsymLapackCall(), Dune::DiagonalMatrix< K, n >::exists(), Dune::DenseMatrix< FieldMatrix< T, ROWS, COLS > >::exists(), Dune::MPIGuard::finalize(), Dune::ParameterTree::get(), Dune::RemoteIndexListModifier< T, A, mode >::insert(), Dune::DiagonalMatrix< K, n >::mmhv(), Dune::DenseMatrix< FieldMatrix< T, ROWS, COLS > >::mmhv(), Dune::DiagonalMatrix< K, n >::mmtv(), Dune::DenseMatrix< FieldMatrix< T, ROWS, COLS > >::mmtv(), Dune::DiagonalMatrix< K, n >::mmv(), Dune::DenseMatrix< FieldMatrix< T, ROWS, COLS > >::mmv(), Dune::DenseMatrix< FieldMatrix< T, ROWS, COLS > >::mtv(), Dune::DiagonalMatrix< K, n >::mv(), Dune::DenseMatrix< FieldMatrix< T, ROWS, COLS > >::mv(), operator int(), Dune::bigunsignedint< k >::operator/(), Dune::ParameterTree::operator[](), Dune::DiagonalRowVectorConst< K, n >::operator[](), Dune::DiagonalRowVector< K, DiagonalMatrixType::rows >::operator[](), Dune::ParameterTree::parseRange(), Dune::DebugStream< thislevel, dlevel, alevel, activator >::pop(), Dune::ParameterTreeParser::readINITree(), Dune::relativePath(), Dune::RemoteIndexListModifier< T, A, mode >::remove(), Dune::RemoteIndexListModifier< T, A, mode >::repairLocalIndexPointers(), Dune::ParameterTree::sub(), Dune::DebugStream< thislevel, dlevel, alevel, activator >::tie(), Dune::lru< _Key, _Tp, _Traits >::touch(), Dune::DiagonalMatrix< K, n >::umhv(), Dune::DenseMatrix< FieldMatrix< T, ROWS, COLS > >::umhv(), Dune::DiagonalMatrix< K, n >::umtv(), Dune::DenseMatrix< FieldMatrix< T, ROWS, COLS > >::umtv(), Dune::DiagonalMatrix< K, n >::umv(), Dune::DenseMatrix< FieldMatrix< T, ROWS, COLS > >::umv(), Dune::DebugStream< thislevel, dlevel, alevel, activator >::untie(), Dune::DiagonalMatrix< K, n >::usmhv(), Dune::DenseMatrix< FieldMatrix< T, ROWS, COLS > >::usmhv(), Dune::DiagonalMatrix< K, n >::usmtv(), Dune::DenseMatrix< FieldMatrix< T, ROWS, COLS > >::usmtv(), Dune::DiagonalMatrix< K, n >::usmv(), Dune::DenseMatrix< FieldMatrix< T, ROWS, COLS > >::usmv(), Dune::DebugStream< thislevel, dlevel, alevel, activator >::~DebugStream(), Dune::fmatrix_assigner< T, n, m >::~fmatrix_assigner(), and Dune::fvector_assigner< T, s >::~fvector_assigner().

Function Documentation

void Dune::Exception::clearHook ( )
inlinestatic

remove all hooks

Dune::Exception::Exception ( )
inline
void Dune::Exception::message ( const std::string &  msg)
inline

store string in internal message buffer

virtual void Dune::ExceptionHook::operator() ( )
pure virtual
std::ostream& Dune::operator<< ( std::ostream &  stream,
const Exception e 
)
inline
void Dune::Exception::registerHook ( ExceptionHook hook)
inlinestatic

add a functor which is called before a Dune::Exception is emitted (see Dune::ExceptionHook)

See also
Dune::ExceptionHook
const std::string & Dune::Exception::what ( ) const
inline

output internal message buffer

Referenced by Dune::operator<<().

virtual Dune::ExceptionHook::~ExceptionHook ( )
inlinevirtual