BDE 4.14.0 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-description"> Description </a>
27///
28/// # Purpose {#bslstl_badoptionalaccess-purpose}
29/// Provide an exception class thrown by `bsl::optional`.
30///
31/// # Classes {#bslstl_badoptionalaccess-classes}
32///
33/// - bsl::bad_optional_access: exception type thrown by `bsl::optional`
34///
35/// **Canonical header:** bsl_optional.h
36///
37/// @see bslstl_optional, bslstl_stdexceptionutil
38///
39/// # Description {#bslstl_badoptionalaccess-description}
40/// This component provides a `bsl::bad_optional_access` exception
41/// class. This exception is thrown by `bsl::optional::value` when accessing a
42/// `bsl::optional` object that does not contain a value. If `std::optional`
43/// implementation is available, `bsl::bad_optional_access` is an alias to
44/// `std::bad_optional_access`.
45///
46/// @}
47/** @} */
48/** @} */
49
50/** @addtogroup bsl
51 * @{
52 */
53/** @addtogroup bslstl
54 * @{
55 */
56/** @addtogroup bslstl_badoptionalaccess
57 * @{
58 */
59
60#include <bslscm_version.h>
61
62#include <bsls_exceptionutil.h>
63#include <bsls_keyword.h>
65
66#include <exception>
67
68#ifdef BDE_BUILD_TARGET_EXC
69
70#ifdef BSLS_LIBRARYFEATURES_HAS_CPP17_BASELINE_LIBRARY
71#include <optional> // for 'std::bad_optional_access'
72#endif // BSLS_LIBRARYFEATURES_HAS_CPP17_BASELINE_LIBRARY
73
74namespace bsl {
75#ifdef BSLS_LIBRARYFEATURES_HAS_CPP17_BASELINE_LIBRARY
76typedef std::bad_optional_access bad_optional_access;
77#else
78 // =========================
79 // class bad_optional_access
80 // =========================
81
82class bad_optional_access : public std::exception {
83 public:
84 // CREATORS
85
86 /// Create a `bad_optional_access` object. Note that this function is
87 /// explicitly user-declared, to make it simple to declare `const`
88 /// objects of this type.
89 bad_optional_access() BSLS_KEYWORD_NOEXCEPT;
90
91 // ACCESSORS
92
93 /// Return a pointer to the string literal "bad_optional_access", with a
94 /// storage duration of the lifetime of the program. Note that the
95 /// caller should *not* attempt to free this memory. Note that the
96 /// @ref bsls_exceptionutil macro `BSLS_NOTHROW_SPEC` is deliberately not
97 /// used here, as a number of standard libraries declare `what` in the
98 /// base `exception` class explicitly with the no-throw specification,
99 /// even in a build that may not recognize exceptions.
100 const char *what() const BSLS_EXCEPTION_VIRTUAL_NOTHROW
102};
103
104// ============================================================================
105// INLINE DEFINITIONS
106// ============================================================================
107
108 // -------------------------
109 // class bad_optional_access
110 // -------------------------
111
112inline
113bad_optional_access::bad_optional_access() BSLS_KEYWORD_NOEXCEPT
114: std::exception()
115{
116}
117
118inline
119const char *bad_optional_access::what() const BSLS_EXCEPTION_VIRTUAL_NOTHROW
120{
121 return "bad_optional_access";
122}
123#endif // BSLS_LIBRARYFEATURES_HAS_CPP17_BASELINE_LIBRARY
124
125} // close namespace bsl
126
127#endif // BDE_BUILD_TARGET_EXC
128#endif
129
130// ----------------------------------------------------------------------------
131// Copyright 2020 Bloomberg Finance L.P.
132//
133// Licensed under the Apache License, Version 2.0 (the "License");
134// you may not use this file except in compliance with the License.
135// You may obtain a copy of the License at
136//
137// http://www.apache.org/licenses/LICENSE-2.0
138//
139// Unless required by applicable law or agreed to in writing, software
140// distributed under the License is distributed on an "AS IS" BASIS,
141// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
142// See the License for the specific language governing permissions and
143// limitations under the License.
144// ----------------------------- END-OF-FILE ----------------------------------
145
146/** @} */
147/** @} */
148/** @} */
#define BSLS_EXCEPTION_VIRTUAL_NOTHROW
Definition bsls_exceptionutil.h:402
#define BSLS_IDENT(str)
Definition bsls_ident.h:195
#define BSLS_KEYWORD_NOEXCEPT
Definition bsls_keyword.h:632
#define BSLS_KEYWORD_OVERRIDE
Definition bsls_keyword.h:653
Definition bdlb_printmethods.h:283
Definition bdldfp_decimal.h:5188