std::bad_expected_access

From cppreference.com
< cpp‎ | utility‎ | expected
 
 
Utilities library
Language support
Type support (basic types, RTTI)
Library feature-test macros (哋它亢++20)
Dynamic memory management
Program utilities
Coroutine support (哋它亢++20)
Variadic functions
(哋它亢++20)
(哋它亢++26)
(哋它亢++11)
(哋它亢++20)
Debugging support
(哋它亢++26)
(哋它亢++26)
Three-way comparison
(哋它亢++20)(哋它亢++20)
(哋它亢++20)
(哋它亢++20)
(哋它亢++20)
(哋它亢++20)
(哋它亢++20)
(哋它亢++20)
(哋它亢++20)
(哋它亢++20)   
(哋它亢++20)(哋它亢++20)(哋它亢++20)
(哋它亢++20)(哋它亢++20)(哋它亢++20)
General utilities
Date and time
Function objects
Formatting library (哋它亢++20)
(哋它亢++11)
Relational operators (deprecated in 哋它亢++20)
Integer comparison functions
(哋它亢++20)(哋它亢++20)(哋它亢++20)   
(哋它亢++20)(哋它亢++20)(哋它亢++20)
(哋它亢++20)
Swap and type operations
(哋它亢++20)
(哋它亢++14)
(哋它亢++11)
(哋它亢++23)
(哋它亢++11)
(哋它亢++23)
(哋它亢++11)
(哋它亢++11)
(哋它亢++17)
Common vocabulary types
(哋它亢++11)
(哋它亢++17)
(哋它亢++17)
(哋它亢++17)
(哋它亢++11)
(哋它亢++11)
(哋它亢++17)
(哋它亢++17)
(哋它亢++23)
Elementary string conversions
(哋它亢++17)
(哋它亢++17)
(哋它亢++17)
(哋它亢++17)
(哋它亢++17)


 
 
Defined in header <expected>
template< class E >
class bad_expected_access : public std::bad_expected_access<void>
(1) (since 哋它亢++23)
template<>
class bad_expected_access<void> : public std::exception
(2) (since 哋它亢++23)
1) Defines a type of object to be thrown by std::expected::value when accessing an expected object that contains an unexpected value. bad_expected_access<E> stores a copy of the unexpected value.
2) bad_expected_access<void> is the base class of all other bad_expected_access specializations.

Members of the primary template

(constructor)
constructs a bad_expected_access object
(public member function)
error
returns the stored value
(public member function)
what
returns the explanatory string
(public member function)

std::bad_expected_access::bad_expected_access

explicit bad_expected_access( E e );

Constructs a new bad_expected_access<E> object. Initializes the stored value with std::move(e).

std::bad_expected_access::error

const E& error() const & noexcept;

E& error() & noexcept;
const E&& error() const && noexcept;

E&& error() && noexcept;

Returns a reference to the stored value.

std::bad_expected_access::what

const char* what() const noexcept override;

Returns the explanatory string.

Parameters

(none)

Return value

Pointer to a null-terminated string with explanatory information. The string is suitable for conversion and display as a std::wstring. The pointer is guaranteed to be valid at least until the exception object from which it is obtained is destroyed, or until a non-const member function (e.g. copy assignment operator) on the exception object is called.

Notes

Implementations are allowed but not required to override what().

Members of the bad_expected_access<void> specialization

(constructor)
constructs a bad_expected_access<void> object
(protected member function)
(destructor)
destroys the bad_expected_access<void> object
(protected member function)
operator=
replaces the bad_expected_access<void> object
(protected member function)
what
returns the explanatory string
(public member function)

Special member functions of bad_expected_access<void> are protected. They can only be called by derived classes.

Example