Difference between revisions of "cpp/error/bad exception"
m (moved cpp/error/exception/bad exception to cpp/error/bad exception) |
m (Text replace - "cpp/error/exception" to "cpp/error") |
||
Line 16: | Line 16: | ||
===Member functions=== | ===Member functions=== | ||
{{dcl list begin}} | {{dcl list begin}} | ||
− | {{dcl list mem ctor | cpp/error | + | {{dcl list mem ctor | cpp/error/bad_exception/bad_exception | constructs the bad_exception object}} |
− | {{dcl list mem vfun | cpp/error | + | {{dcl list mem vfun | cpp/error/bad_exception/what | returns the explanatory string}} |
{{dcl list end}} | {{dcl list end}} | ||
− | {{cpp/error | + | {{cpp/error/exception/inherit}} |
===Example=== | ===Example=== |
Revision as of 00:35, 29 April 2012
Template:cpp/error/sidebar Template:ddcl list begin <tr class="t-dsc-header">
<td><exception>
<td></td> <td></td> </tr> <tr class="t-dcl ">
<td class="t-dcl-nopad"><td class="t-dcl-nopad"> </td> <td class="t-dcl-nopad"> </td> </tr> Template:ddcl list end
std::bad_exception
is the type of the exception thrown by the C++ runtime in the following situations:
1) If a dynamic exception specification is violated and std::unexpected throws or rethrows an exception that still violates the exception specification, but the exception specification allows std::bad_exception
, std::bad_exception
is thrown.
2) If std::exception_ptr stores a copy of the caught exception and if the copy constructor of the exception object caught by current_exception throws an exception, the captured exception is an instance of std::bad_exception
.
Contents |
Member functions
constructs the bad_exception 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 )
|
Example
#include <iostream> #include <exception> #include <stdexcept> void my_unexp() { throw; } void test() throw(std::bad_exception) { throw std::runtime_error("test"); } int main() { std::set_unexpected(my_unexp); try { test(); } catch(const std::bad_exception& e) { std::cerr << "Caught " << e.what() << '\n'; } }
Output:
Caught std::bad_exception