xentara-utils v2.0.4
The Xentara Utility Library
|
A class that detects whether the stack is currently being wound up. More...
#include <xentara/utils/eh/ExceptionGuard.hpp>
Public Member Functions | |
ExceptionGuard ()=default | |
Default constructor. | |
ExceptionGuard (const ExceptionGuard &) | |
This class is copyable, but the state is not actually copied. | |
auto | operator= (const ExceptionGuard &rhs) -> ExceptionGuard |
This class is assigneble, but the state is not actually copied. | |
operator bool () const | |
Checks whether an exception has been thrown since the object has been constructed. | |
A class that detects whether the stack is currently being wound up.
This class can be used to determine whether the stack frame that thje object has been constructed in is currently being wound up. This is useful to determine whether it is safe to throw an exception from a destructor or not.
Many classes need to perform different steps in the destructor, depending on whether an exception was thrown or not. Consider, for example, a class that implements buffered file writing. In the destructor, the object must perform different cleanup, depending on whether an exception was thrown or not:
The class ExceptionGuard can be used like this to distinguish between the two cases:
|
default |
Default constructor.
xentara::utils::eh::ExceptionGuard::ExceptionGuard | ( | const ExceptionGuard & | ) |
This class is copyable, but the state is not actually copied.
|
explicit |
Checks whether an exception has been thrown since the object has been constructed.
auto xentara::utils::eh::ExceptionGuard::operator= | ( | const ExceptionGuard & | rhs | ) | -> ExceptionGuard |
This class is assigneble, but the state is not actually copied.