Dune Core Modules (2.5.0)

exceptions.hh
Go to the documentation of this file.
1// -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2// vi: set et ts=4 sw=2 sts=2:
3
4#ifndef DUNE_EXCEPTIONS_HH
5#define DUNE_EXCEPTIONS_HH
6
7#include <exception>
8#include <string>
9#include <sstream>
10
11namespace Dune {
12
71 /* forward declarations */
72 class Exception;
73 struct ExceptionHook;
74
93 : public std::exception
94 {
95 public:
96 Exception ();
97 void message(const std::string &msg);
98 virtual const char* what() const noexcept;
99 static void registerHook (ExceptionHook * hook);
100 static void clearHook ();
101 private:
102 std::string _message;
103 static ExceptionHook * _hook;
104 };
105
172 {
173 virtual ~ExceptionHook() {}
174 virtual void operator () () = 0;
175 };
176
177 inline std::ostream& operator<<(std::ostream &stream, const Exception &e)
178 {
179 return stream << e.what();
180 }
181
182#ifndef DOXYGEN
183 // the "format" the exception-type gets printed. __FILE__ and
184 // __LINE__ are standard C-defines, the GNU cpp-infofile claims that
185 // C99 defines __func__ as well. __FUNCTION__ is a GNU-extension
186#define THROWSPEC(E) # E << " [" << __func__ << ":" << __FILE__ << ":" << __LINE__ << "]: "
187#endif // DOXYGEN
188
214 // this is the magic: use the usual do { ... } while (0) trick, create
215 // the full message via a string stream and throw the created object
216#define DUNE_THROW(E, m) do { E th__ex; std::ostringstream th__out; \
217 th__out << THROWSPEC(E) << m; th__ex.message(th__out.str()); throw th__ex; \
218} while (0)
219
229 class IOError : public Exception {};
230
239 class MathError : public Exception {};
240
252 class RangeError : public Exception {};
253
261 class NotImplemented : public Exception {};
262
269 class SystemError : public Exception {};
270
274 class OutOfMemoryError : public SystemError {};
275
280
285 class ParallelError : public Exception {};
286
287} // end namespace
288
289#endif
Base class for Dune-Exceptions.
Definition: exceptions.hh:94
Default exception class for I/O errors.
Definition: exceptions.hh:229
Default exception if a function was called while the object is not in a valid state for that function...
Definition: exceptions.hh:279
Default exception class for mathematical errors.
Definition: exceptions.hh:239
Default exception for dummy implementations.
Definition: exceptions.hh:261
Default exception if memory allocation fails.
Definition: exceptions.hh:274
Default exception if an error in the parallel communication of the programm occurred.
Definition: exceptions.hh:285
Default exception class for range errors.
Definition: exceptions.hh:252
Default exception class for OS errors.
Definition: exceptions.hh:269
static void registerHook(ExceptionHook *hook)
add a functor which is called before a Dune::Exception is emitted (see Dune::ExceptionHook)
Definition: exceptions.cc:20
static void clearHook()
remove all hooks
Definition: exceptions.cc:25
void message(const std::string &msg)
store string in internal message buffer
Definition: exceptions.cc:30
virtual const char * what() const noexcept
output internal message buffer
Definition: exceptions.cc:35
Dune namespace.
Definition: alignment.hh:11
Base class to add a hook to the Dune::Exception.
Definition: exceptions.hh:172
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Nov 23, 23:29, 2024)