Gromacs
2024.4
|
#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.
Public Member Functions | |
ExceptionInitializer (const char *reason) | |
Creates an initialized with the given string as the reason. More... | |
ExceptionInitializer (const std::string &reason) | |
Creates an initialized with the given string as the reason. More... | |
bool | hasNestedExceptions () const |
Returns true if addCurrentExceptionAsNested() has been called. More... | |
void | addCurrentExceptionAsNested () |
Adds the currently caught exception as a nested exception. More... | |
template<class Exception > | |
void | addNested (const Exception &ex) |
Adds the specified exception as a nested exception. More... | |
|
inline |
Creates an initialized with the given string as the reason.
[in] | reason | Detailed reason for the exception. |
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.
|
inline |
Creates an initialized with the given string as the reason.
[in] | reason | Detailed reason for the exception. |
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.
|
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.
|
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.
|
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.