BDE 4.39.x Production Release
Loading...
Searching...
No Matches
bslstl_badoptionalaccess.h
Go to the documentation of this file.
1/// @file bslstl_badoptionalaccess.h
2///
3/// The content of this file has been pre-processed for Doxygen.
4///
5
6
7// bslstl_badoptionalaccess.h -*-C++-*-
8#ifndef INCLUDED_BSLSTL_BADOPTIONALACCESS
9#define INCLUDED_BSLSTL_BADOPTIONALACCESS
10
11#include <bsls_ident.h>
12BSLS_IDENT("$Id: $")
13
14/// @defgroup bslstl_badoptionalaccess bslstl_badoptionalaccess
15/// @brief Provide an exception class thrown by `bsl::optional`.
16/// @addtogroup bsl
17/// @{
18/// @addtogroup bslstl
19/// @{
20/// @addtogroup bslstl_badoptionalaccess
21/// @{
22///
23/// <h1> Outline </h1>
24/// * <a href="#bslstl_badoptionalaccess-purpose"> Purpose</a>
25/// * <a href="#bslstl_badoptionalaccess-classes"> Classes </a>
26/// * <a href="#bslstl_badoptionalaccess-canonical-header"> Canonical Header </a>
27/// * <a href="#bslstl_badoptionalaccess-description"> Description </a>
28///
29/// # Purpose {#bslstl_badoptionalaccess-purpose}
30/// Provide an exception class thrown by `bsl::optional`.
31///
32/// # Classes {#bslstl_badoptionalaccess-classes}
33///
34/// - bsl::bad_optional_access: exception type thrown by `bsl::optional`
35///
36/// # Canonical Header {#bslstl_badoptionalaccess-canonical-header}
37/// bsl_optional.h
38///
39/// @see bslstl_optional, bslstl_stdexceptionutil
40///
41/// # Description {#bslstl_badoptionalaccess-description}
42/// This component provides a `bsl::bad_optional_access` exception
43/// class. This exception is thrown by `bsl::optional::value` when accessing a
44/// `bsl::optional` object that does not contain a value. If `std::optional`
45/// implementation is available, `bsl::bad_optional_access` is an alias to
46/// `std::bad_optional_access`.
47///
48/// @}
49/** @} */
50/** @} */
51
52/** @addtogroup bsl
53 * @{
54 */
55/** @addtogroup bslstl
56 * @{
57 */
58/** @addtogroup bslstl_badoptionalaccess
59 * @{
60 */
61
62#include <bslscm_version.h>
63
64#include <bsls_exceptionutil.h>
65#include <bsls_keyword.h>
67
68#include <exception>
69
70#ifdef BDE_BUILD_TARGET_EXC
71
72#if defined(BSLS_LIBRARYFEATURES_HAS_CPP17_BASELINE_LIBRARY) && \
73 !(defined(BSLS_LIBRARYFEATURES_FORCE_ABI_ENABLED) && \
74 (BSLS_LIBRARYFEATURES_FORCE_ABI_ENABLED < 17))
75 #define BSLSTL_BAD_OPTIONAL_ACCESS_IS_ALIASED 1
76#endif // Has C++17 and not disabled
77
78#ifdef BSLSTL_BAD_OPTIONAL_ACCESS_IS_ALIASED
79 #include <optional> // for 'std::bad_optional_access'
80#endif // BSLSTL_BAD_OPTIONAL_ACCESS_IS_ALIASED
81
82namespace bsl {
83#ifdef BSLSTL_BAD_OPTIONAL_ACCESS_IS_ALIASED
84typedef std::bad_optional_access bad_optional_access;
85#else
86 // =========================
87 // class bad_optional_access
88 // =========================
89
90class bad_optional_access : public std::exception {
91 public:
92 // CREATORS
93
94 /// Create a @ref bad_optional_access object.
95 /// \note Note that this function is
96 /// explicitly user-declared, to make it simple to declare `const`
97 /// objects of this type.
98 bad_optional_access() BSLS_KEYWORD_NOEXCEPT;
99
100 // ACCESSORS
101
102 /// Return a pointer to the string literal "bad_optional_access", with a storage duration of the lifetime of the program.
103 ///
104 /// \note Note that the
105 /// caller should *not* attempt to free this memory.
106 /// \note Note that the
107 /// @ref bsls_exceptionutil macro `BSLS_NOTHROW_SPEC` is deliberately not
108 /// used here, as a number of standard libraries declare `what` in the
109 /// base `exception` class explicitly with the no-throw specification,
110 /// even in a build that may not recognize exceptions.
111 const char *what() const BSLS_EXCEPTION_VIRTUAL_NOTHROW
113};
114
115// ============================================================================
116// INLINE DEFINITIONS
117// ============================================================================
118
119 // -------------------------
120 // class bad_optional_access
121 // -------------------------
122
123inline
124bad_optional_access::bad_optional_access() BSLS_KEYWORD_NOEXCEPT
125: std::exception()
126{
127}
128
129inline
130const char *bad_optional_access::what() const BSLS_EXCEPTION_VIRTUAL_NOTHROW
131{
132 return "bad_optional_access";
133}
134#endif // else - BSLSTL_BAD_OPTIONAL_ACCESS_IS_ALIASED
135
136} // close namespace bsl
137
138#endif // BDE_BUILD_TARGET_EXC
139
140#endif
141
142// ----------------------------------------------------------------------------
143// Copyright 2020 Bloomberg Finance L.P.
144//
145// Licensed under the Apache License, Version 2.0 (the "License");
146// you may not use this file except in compliance with the License.
147// You may obtain a copy of the License at
148//
149// http://www.apache.org/licenses/LICENSE-2.0
150//
151// Unless required by applicable law or agreed to in writing, software
152// distributed under the License is distributed on an "AS IS" BASIS,
153// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
154// See the License for the specific language governing permissions and
155// limitations under the License.
156// ----------------------------- END-OF-FILE ----------------------------------
157
158/** @} */
159/** @} */
160/** @} */
#define BSLS_EXCEPTION_VIRTUAL_NOTHROW
Definition bsls_exceptionutil.h:402
#define BSLS_IDENT(str)
BSLS_IDENT() - insert string into .comment binary segment (if supported)
Definition bsls_ident.h:238
#define BSLS_KEYWORD_NOEXCEPT
Definition bsls_keyword.h:674
#define BSLS_KEYWORD_OVERRIDE
Definition bsls_keyword.h:695
Definition bdlat_valuetypefunctions.h:939
Definition bdldfp_decimal.h:5549