#include <gromacs/utility/exceptions.h>
Provides information for Gromacs exception constructors.
This class exists to implement common functionality for initializing all Gromacs exceptions without having extra code in each exception class. In simple cases, it can be implicitly constructed by passing a simple string to an exception constructor. If more complex initialization is necessary, it is possible to explicitly construct an object of this type and then call other methods to add information before actually creating the exception object.
- Todo:
- With the exception of the reason string, information added with this class is not currently accessible through any public API, except for calling printFatalErrorMessage(), formatExceptionMessageToString() or formatExceptionMessageToFile(). This is not implemented as there is not yet need for it, and it is not clear what would be the best alternative for the access. It should be possible to refactor the internal implementation to suit the needs of such external access without requiring changes in code that throws these exceptions.
gmx::ExceptionInitializer::ExceptionInitializer |
( |
const char * |
reason | ) |
|
|
inline |
Creates an initialized with the given string as the reason.
- Parameters
-
[in] | reason | Detailed reason for the exception. |
- Exceptions
-
std::bad_alloc | if out of memory. |
This constructor is not explicit to allow constructing exceptions with a plain string argument given to the constructor without adding extra code to each exception class.
gmx::ExceptionInitializer::ExceptionInitializer |
( |
const std::string & |
reason | ) |
|
|
inline |
Creates an initialized with the given string as the reason.
- Parameters
-
[in] | reason | Detailed reason for the exception. |
- Exceptions
-
std::bad_alloc | if out of memory. |
This constructor is not explicit to allow constructing exceptions with a plain string argument given to the constructor without adding extra code to each exception class.
void gmx::ExceptionInitializer::addCurrentExceptionAsNested |
( |
| ) |
|
|
inline |
Adds the currently caught exception as a nested exception.
May be called multiple times; all provided exceptions will be added in a list of nested exceptions.
Must not be called outside a catch block.
template<class Exception >
void gmx::ExceptionInitializer::addNested |
( |
const Exception & |
ex | ) |
|
|
inline |
Adds the specified exception as a nested exception.
May be called multiple times; all provided exceptions will be added in a list of nested exceptions.
This is equivalent to throwing ex
and calling addCurrentExceptionAsNested() in the catch block, but potentially more efficient.
bool gmx::ExceptionInitializer::hasNestedExceptions |
( |
| ) |
const |
|
inline |
Returns true if addCurrentExceptionAsNested() has been called.
Provided for convenience for cases where exceptions will be added conditionally, and the caller wants to check whether any excetions were actually added.
The documentation for this class was generated from the following file: