The Dune-exceptions are designed to allow a simple derivation of subclasses and to accept a text written in the '<<' syntax.
Example of usage:
...
...
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();
}
...
try {
...
std::cerr << "I/O error: " << e << std::endl;
return 1;
std::cerr << "Generic Dune error: " << e << std::endl;
return 2;
}
}
A few common exception classes.
int main(int argc, char **argv)
Definition mpi_collective_benchmark.cc:293
#define DUNE_THROW(E, m)
Definition exceptions.hh:218
Base class for Dune-Exceptions.
Definition exceptions.hh:96
Default exception class for I/O errors.
Definition exceptions.hh:231
- See also
- exceptions.hh for detailed info
◆ DUNE_THROW
#define DUNE_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
-
E | exception class derived from Dune::Exception |
m | reason 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.
- 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)
◆ clearHook()
void Dune::Exception::clearHook |
( |
| ) |
|
|
static |
◆ Exception()
Dune::Exception::Exception |
( |
| ) |
|
◆ message()
void Dune::Exception::message |
( |
const std::string & |
msg | ) |
|
store string in internal message buffer
◆ operator()()
virtual void Dune::ExceptionHook::operator() |
( |
| ) |
|
|
pure virtual |
◆ operator<<()
std::ostream & Dune::operator<< |
( |
std::ostream & |
stream, |
|
|
const Exception & |
e |
|
) |
| |
|
inline |
◆ registerHook()
◆ what()
const char * Dune::Exception::what |
( |
| ) |
const |
|
overridenoexcept |
output internal message buffer
◆ ~ExceptionHook()
virtual Dune::ExceptionHook::~ExceptionHook |
( |
| ) |
|
|
inlinevirtual |