BloombergLP::bslma::ExceptionGuard

Guard that verifies an object is unchanged if an exception is thrown.

Synopsis

Declared in <bslma_exceptionguard.h>

template<class OBJECT>
class ExceptionGuard;

Description

This class provides a mechanism to verify the strong exception guarantee in exception-throwing code. On construction, this class stores a copy of an object of the parameterized type OBJECT and the address of that object. On destruction, if release was not invoked, it will verify the value of the object is the same as the value of the copy created on construction. This class requires the copy constructor and operator == to be tested before use.

Member Functions

NameDescription
ExceptionGuard [constructor]Create the exception guard for the specified object at the specified line number. Optionally, specify basicAllocator used to supply memory.
~ExceptionGuard [destructor]Destroy the exception guard. If the guard was not released, verify that the state of the object supplied at construction has not change.
release Release the guard from verifying the state of the object.
resetValue Reset the expected state of the guarded object, if an exception should propagate past this guard, to the specified value, which is set from the specified line.