BDE 4.39.x 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-canonical-header"> Canonical Header </a>
27/// * <a href="#bslstl_exception-description"> Description </a>
28/// * <a href="#bslstl_exception-usage"> Usage </a>
29/// * <a href="#bslstl_exception-example-1-determining-if-the-stack-is-being-unwound"> Example 1: Determining if the stack is being unwound. </a>
30///
31/// # Purpose {#bslstl_exception-purpose}
32/// Provide an implementation of @ref uncaught_exceptions .
33///
34/// # Classes {#bslstl_exception-classes}
35///
36///
37/// # Canonical Header {#bslstl_exception-canonical-header}
38/// bsl_exception.h
39///
40/// # Description {#bslstl_exception-description}
41/// This component defines a function `bsl::uncaught_exceptions`.
42/// For C++17 and later, this is an alias for `std::uncaught_exceptions`. Before
43/// C++17, we emulate the functionality.
44///
45/// ## Usage {#bslstl_exception-usage}
46///
47///
48/// In this section we show intended use of this component.
49///
50/// ### Example 1: Determining if the stack is being unwound. {#bslstl_exception-example-1-determining-if-the-stack-is-being-unwound}
51///
52///
53/// Suppose we have a class that does some processing in it's destructor, but
54/// we don't want to do this if an exception is "in flight". `bslmt::OnceGuard`
55/// is an example of this kind of functionality.
56///
57/// First, we create a class with an `int d_exception_count` member variable,
58/// and record the number of in-flight exceptions in the constructor.
59/// @code
60/// struct ExceptionAware {
61/// ExceptionAware() : d_exception_count(bsl::uncaught_exceptions()) {}
62/// ~ExceptionAware();
63/// int d_exception_count;
64/// };
65/// @endcode
66/// Then, we implement the destructor
67/// @code
68/// ExceptionAware::~ExceptionAware () {
69/// if (bsl::uncaught_exceptions() > d_exception_count) {
70/// // The stack is being unwound
71/// }
72/// else {
73/// // The object is being destroyed normally
74/// }
75/// }
76/// @endcode
77/// @}
78/** @} */
79/** @} */
80
81/** @addtogroup bsl
82 * @{
83 */
84/** @addtogroup bslstl
85 * @{
86 */
87/** @addtogroup bslstl_exception
88 * @{
89 */
90
91#include <bslscm_version.h>
92
95
96#include <exception>
97
98namespace bsl {
99#if defined (BSLS_LIBRARYFEATURES_HAS_CPP17_BASELINE_LIBRARY) && \
100 !(defined(BSLS_LIBRARYFEATURES_FORCE_ABI_ENABLED) && \
101 (BSLS_LIBRARYFEATURES_FORCE_ABI_ENABLED < 17))
102
103 #define BSLSTL_EXCEPTION_UNCAUGHT_EXCEPTIONS_IS_ALIAS
104 using std::uncaught_exceptions;
105#endif // BSLS_LIBRARYFEATURES_HAS_CPP17_BASELINE_LIBRARY && not disabled
106
107#ifndef BSLSTL_EXCEPTION_UNCAUGHT_EXCEPTIONS_IS_ALIAS
108 /// Return the number of exceptions that have been thrown or rethrown in
109 /// the current thread that have not been caught. If the C++17 baseline
110 /// library is not available, this function may return 1 even if more
111 /// than 1 uncaught exception exists, but is guaranteed to return 0 if
112 /// there are no uncaught exceptions.
113 int uncaught_exceptions() throw();
114#endif // ndef BSLSTL_EXCEPTION_UNCAUGHT_EXCEPTIONS_IS_ALIAS
115} // close namespace bsl
116
117#endif
118
119// ----------------------------------------------------------------------------
120// Copyright 2023 Bloomberg Finance L.P.
121//
122// Licensed under the Apache License, Version 2.0 (the "License");
123// you may not use this file except in compliance with the License.
124// You may obtain a copy of the License at
125//
126// http://www.apache.org/licenses/LICENSE-2.0
127//
128// Unless required by applicable law or agreed to in writing, software
129// distributed under the License is distributed on an "AS IS" BASIS,
130// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
131// See the License for the specific language governing permissions and
132// limitations under the License.
133// ----------------------------- END-OF-FILE ----------------------------------
134
135/** @} */
136/** @} */
137/** @} */
#define BSLS_IDENT(str)
BSLS_IDENT() - insert string into .comment binary segment (if supported)
Definition bsls_ident.h:238
Definition bdlat_valuetypefunctions.h:939
int uncaught_exceptions()