std:: bad_exception
From cppreference.com
C++
Utilities library
|
|
Diagnostics library
|
|
std::bad_exception
Member functions | ||||
Defined in header
<exception>
|
||
class
bad_exception
;
|
||
std::bad_exception
is the type of the exception thrown by the C++ runtime in the following situations:
|
(since C++11) |
|
(until C++17) |
Inheritance diagram
All member functions of
|
(since C++26) |
Member functions
constructs the
bad_exception
object
(public member function) |
|
copies the object
(public member function) |
|
[virtual]
|
returns the explanatory string
(virtual public member function) |
Inherited from std:: exception
Member functions
[virtual]
|
destroys the exception object
(virtual public member function of
std::exception
)
|
[virtual]
|
returns an explanatory string
(virtual public member function of
std::exception
)
|
Notes
Feature-test macro | Value | Std | Feature |
---|---|---|---|
__cpp_lib_constexpr_exceptions
|
202411L | (C++26) | constexpr for exception types |
Example
Compiles only in C++14 or earlier modes (may issue warnings).
Run this code
#include <exception> #include <iostream> #include <stdexcept> void my_unexp() { throw; } void test() throw(std::bad_exception) // Dynamic exception specifications // are deprecated in C++11 { throw std::runtime_error("test"); } int main() { std::set_unexpected(my_unexp); // Deprecated in C++11, removed in C++17 try { test(); } catch (const std::bad_exception& e) { std::cerr << "Caught " << e.what() << '\n'; } }
Possible output:
Caught std::bad_exception
Retrieved from "
https://en.cppreference.com/mwiki/index.php?title=cpp/error/bad_exception&oldid=177875
"