BDE 4.14.0 Production release
Loading...
Searching...
No Matches
bslstl_exception

Detailed Description

Outline

Purpose

Provide an implementation of uncaught_exceptions .

Classes

Canonical header: bsl_exception.h

Description

This component defines a function bsl::uncaught_exceptions. For C++17 and later, this is an alias for std::uncaught_exceptions. Before C++17, we emulate the functionality.

Usage

In this section we show intended use of this component.

Example 1: Determining if the stack is being unwound.

Suppose we have a class that does some processing in it's destructor, but we don't want to do this if an exception is "in flight". bslmt::OnceGuard is an example of this kind of functionality.

First, we create a class with an int d_exception_count member variable, and record the number of in-flight exceptions in the constructor.

struct ExceptionAware {
ExceptionAware() : d_exception_count(bsl::uncaught_exceptions()) {}
~ExceptionAware();
int d_exception_count;
};
Definition bdlb_printmethods.h:283

Then, we implement the destructor

ExceptionAware::~ExceptionAware () {
if (bsl::uncaught_exceptions() > d_exception_count) {
// The stack is being unwound
}
else {
// The object is being destroyed normally
}
}
int uncaught_exceptions()