BDE 4.14.0 Production release
Loading...
Searching...
No Matches
bslstl_exception.h
Go to the documentation of this file.
1/// @file bslstl_exception.h
2///
3/// The content of this file has been pre-processed for Doxygen.
4///
5
6
7// bslstl_exception.h -*-C++-*-
8#ifndef INCLUDED_BSLSTL_EXCEPTION
9#define INCLUDED_BSLSTL_EXCEPTION
10
11#include <bsls_ident.h>
12BSLS_IDENT("$Id: $")
13
14/// @defgroup bslstl_exception bslstl_exception
15/// @brief Provide an implementation of `uncaught_exceptions`.
16/// @addtogroup bsl
17/// @{
18/// @addtogroup bslstl
19/// @{
20/// @addtogroup bslstl_exception
21/// @{
22///
23/// <h1> Outline </h1>
24/// * <a href="#bslstl_exception-purpose"> Purpose</a>
25/// * <a href="#bslstl_exception-classes"> Classes </a>
26/// * <a href="#bslstl_exception-description"> Description </a>
27/// * <a href="#bslstl_exception-usage"> Usage </a>
28/// * <a href="#bslstl_exception-example-1-determining-if-the-stack-is-being-unwound"> Example 1: Determining if the stack is being unwound. </a>
29///
30/// # Purpose {#bslstl_exception-purpose}
31/// Provide an implementation of @ref uncaught_exceptions .
32///
33/// # Classes {#bslstl_exception-classes}
34///
35///
36/// **Canonical header:** bsl_exception.h
37///
38/// # Description {#bslstl_exception-description}
39/// This component defines a function `bsl::uncaught_exceptions`.
40/// For C++17 and later, this is an alias for `std::uncaught_exceptions`. Before
41/// C++17, we emulate the functionality.
42///
43/// ## Usage {#bslstl_exception-usage}
44///
45///
46/// In this section we show intended use of this component.
47///
48/// ### Example 1: Determining if the stack is being unwound. {#bslstl_exception-example-1-determining-if-the-stack-is-being-unwound}
49///
50///
51/// Suppose we have a class that does some processing in it's destructor, but
52/// we don't want to do this if an exception is "in flight". `bslmt::OnceGuard`
53/// is an example of this kind of functionality.
54///
55/// First, we create a class with an `int d_exception_count` member variable,
56/// and record the number of in-flight exceptions in the constructor.
57/// @code
58/// struct ExceptionAware {
59/// ExceptionAware() : d_exception_count(bsl::uncaught_exceptions()) {}
60/// ~ExceptionAware();
61/// int d_exception_count;
62/// };
63/// @endcode
64/// Then, we implement the destructor
65/// @code
66/// ExceptionAware::~ExceptionAware () {
67/// if (bsl::uncaught_exceptions() > d_exception_count) {
68/// // The stack is being unwound
69/// }
70/// else {
71/// // The object is being destroyed normally
72/// }
73/// }
74/// @endcode
75/// @}
76/** @} */
77/** @} */
78
79/** @addtogroup bsl
80 * @{
81 */
82/** @addtogroup bslstl
83 * @{
84 */
85/** @addtogroup bslstl_exception
86 * @{
87 */
88
89#include <bslscm_version.h>
90
93
94#include <exception>
95
96namespace bsl {
97#ifdef BSLS_LIBRARYFEATURES_HAS_CPP17_BASELINE_LIBRARY
98 using std::uncaught_exceptions;
99#else
100 /// Return the number of exceptions that have been thrown or rethrown in
101 /// the current thread that have not been caught. If the C++17 baseline
102 /// library is not available, this function may return 1 even if more
103 /// than 1 uncaught exception exists, but if guaranteed to return 0 if
104 /// there are no uncaught exceptions.
105 int uncaught_exceptions() throw();
106#endif
107} // close namespace bsl
108
109#endif
110
111// ----------------------------------------------------------------------------
112// Copyright 2023 Bloomberg Finance L.P.
113//
114// Licensed under the Apache License, Version 2.0 (the "License");
115// you may not use this file except in compliance with the License.
116// You may obtain a copy of the License at
117//
118// http://www.apache.org/licenses/LICENSE-2.0
119//
120// Unless required by applicable law or agreed to in writing, software
121// distributed under the License is distributed on an "AS IS" BASIS,
122// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
123// See the License for the specific language governing permissions and
124// limitations under the License.
125// ----------------------------- END-OF-FILE ----------------------------------
126
127/** @} */
128/** @} */
129/** @} */
#define BSLS_IDENT(str)
Definition bsls_ident.h:195
Definition bdlb_printmethods.h:283
int uncaught_exceptions()