Exceptions
Diagnostics
Collaboration diagram for Exceptions:

## Classes

class | __cxxabiv1::__forced_unwind
class | std::bad_alloc
class | std::bad_any_cast
class | std::experimental::fundamentals_v1::bad_any_cast
class | std::bad_cast
class | std::bad_exception
class | std::bad_function_call
class | std::bad_optional_access
class | std::experimental::fundamentals_v1::bad_optional_access
class | std::bad_typeid
class | std::bad_weak_ptr
class | std::domain_error
class | std::exception
class | std::__unspecified__::exception_ptr
struct | __gnu_cxx::forced_error
class | std::future_error
class | std::invalid_argument
class | std::length_error
class | std::logic_error
class | std::nested_exception
class | std::out_of_range
class | std::overflow_error
class | std::range_error
class | __gnu_cxx::recursive_init_error
class | std::regex_error
class | std::runtime_error
class | std::system_error
class | std::underflow_error

## Typedefs

typedef void(* | std::terminate_handler) ()
typedef void(* | std::unexpected_handler) ()

## Functions

void | __gnu_cxx::__verbose_terminate_handler ()
exception_ptr | std::current_exception () noexcept
terminate_handler | std::get_terminate () noexcept
unexpected_handler | std::get_unexpected () noexcept
template<typename _Ex>
exception_ptr | std::make_exception_ptr (_Ex __ex) noexcept
void | std::rethrow_exception (exception_ptr)
template<typename _Ex>
void | std::rethrow_if_nested (const _Ex &__ex)
terminate_handler | std::set_terminate (terminate_handler) noexcept
unexpected_handler | std::set_unexpected (unexpected_handler) noexcept
void | std::terminate () noexcept
template<typename _Tp>
void | std::throw_with_nested (_Tp &&__t)
int | std::uncaught_exceptions () noexcept
void | std::unexpected ()

## Variables

class __attribute((__abi_tag__("cxx11"))) failure typedef _Ios_Fmtflags | std::ios_base::fmtflags

## Detailed Description

Since
  C++98

Classes and functions for reporting errors via exceptions.

## Typedef Documentation

## terminate_handler

typedef void(* std::terminate_handler) ()

If you write a replacement terminate handler, it must be of this type.

Definition at line 66 of file exception.

## unexpected_handler

typedef void(* std::unexpected_handler) ()

If you write a replacement unexpected handler, it must be of this type.

Definition at line 82 of file exception.

## Function Documentation

## __verbose_terminate_handler()

void __gnu_cxx::__verbose_terminate_handler | ( |  | ) |

A replacement for the standard terminate_handler which prints more information about the terminating exception (if any) on stderr.

Call

std::set_terminate(__gnu_cxx::__verbose_terminate_handler)
std::set_terminate
terminate_handler set_terminate(terminate_handler) noexcept
Takes a new handler function as an argument, returns the old function.
__gnu_cxx::__verbose_terminate_handler
void __verbose_terminate_handler()
A replacement for the standard terminate_handler which prints more information about the terminating ...

to use. For more info, see http://gcc.gnu.org/onlinedocs/libstdc++/manual/bk01pt02ch06s02.html

In 3.4 and later, this is on by default.

References __verbose_terminate_handler().

Referenced by __verbose_terminate_handler().

## current_exception()

exception_ptr std::current_exception | ( |  | ) |

noexcept

Obtain an exception_ptr to the currently handled exception.

If there is none, or the currently handled exception is foreign, return the null value.

Since
  C++11

References make_exception_ptr().

Referenced by std::nested_exception::nested_exception(), and make_exception_ptr().

## get_terminate()

terminate_handler std::get_terminate | ( |  | ) |

noexcept

Return the current terminate handler.

## get_unexpected()

unexpected_handler std::get_unexpected | ( |  | ) |

noexcept

Return the current unexpected handler.

Since
  C++11

Deprecated
  Removed from the C++ standard in C++17

## make_exception_ptr()

template<typename _Ex>

exception_ptr std::make_exception_ptr | ( | _Ex | __ex | ) |

noexcept

Obtain an exception_ptr pointing to a copy of the supplied object.

Definition at line 249 of file exception_ptr.h.

References current_exception().

Referenced by current_exception().

## rethrow_exception()

void std::rethrow_exception | ( | exception_ptr |  | ) |

Throw the object pointed to by the exception_ptr.

References rethrow_exception().

Referenced by std::__basic_future< _Res & >::_M_get_result(), rethrow_exception(), and std::nested_exception::rethrow_nested().

## rethrow_if_nested()

template<typename _Ex>

void std::rethrow_if_nested | ( | const _Ex & | __ex | ) |

inline

Rethrow a nested exception

If __ex contains a std::nested_exception object, call its rethrow_nested() member to rethrow the stored exception.

After catching an exception thrown by a call to std::throw_with_nested this function can be used to rethrow the exception that was active when std::throw_with_nested was called.

Since
  C++11

Definition at line 208 of file nested_exception.h.

## set_terminate()

terminate_handler std::set_terminate | ( | terminate_handler |  | ) |

noexcept

Takes a new handler function as an argument, returns the old function.

References set_terminate().

Referenced by set_terminate().

## set_unexpected()

unexpected_handler std::set_unexpected | ( | unexpected_handler |  | ) |

noexcept

Takes a new handler function as an argument, returns the old function.

Deprecated
  Removed from the C++ standard in C++17

## terminate()

void std::terminate | ( |  | ) |

noexcept

The runtime will call this function if exception handling must be abandoned for any reason. It can also be called by the user.

Referenced by std::nested_exception::rethrow_nested().

## throw_with_nested()

template<typename _Tp>

void std::throw_with_nested | ( | _Tp && | __t | ) |

inline

Throw an exception that also stores the currently active exception.

If _Tp is derived from std::nested_exception or is not usable as a base-class, throws a copy of __t. Otherwise, throws an object of an implementation-defined type derived from both _Tp and std::nested_exception, containing a copy of __t and the result of std::current_exception().

In other words, throws the argument as a new exception that contains the currently active exception nested within it. This is intended for use in a catch handler to replace the caught exception with a different type, while still preserving the original exception. When the new exception is caught, the nested exception can be rethrown by using std::rethrow_if_nested.

This can be used at API boundaries, for example to catch a library's internal exception type and rethrow it nested with a std::runtime_error, or vice versa.

Since
  C++11

Definition at line 148 of file nested_exception.h.

References forward().

## uncaught_exceptions()

int std::uncaught_exceptions | ( |  | ) |

noexcept

[18.6.4]/1: 'Returns true after completing evaluation of a throw-expression until either completing initialization of the exception-declaration in the matching handler or entering unexpected() due to the throw; or after entering terminate() for any reason other than an explicit call to terminate(). [Note: This includes stack unwinding [15.2]. end note]'

2: 'When uncaught_exception() is true, throwing an exception can result in a call of 1terminate()` (15.5.1).' */

bool uncaught_exception() noexcept ;

c++17 or gnu++98 define __cpp_lib_uncaught_exceptions
/** The number of uncaught exceptions.

Since
  C++17, or any non-strict mode, e.g. -std=gnu++98

See also
  uncaught_exception()

## unexpected()

void std::unexpected | ( |  | ) |

The runtime will call this function if an exception is thrown which violates the function's exception specification.

Deprecated
  Removed from the C++ standard in C++17

## Variable Documentation

## fmtflags

class __attribute ((__abi_tag__ ("cxx11"))) failure typedef _Ios_Fmtflags std::ios_base::fmtflags

These are thrown to indicate problems with io.

27.4.2.1.1 Class ios_base::failure

This is a bitmask type.

`_Ios_Fmtflags is` implementation-defined, but it is valid to perform bitwise operations on these values and expect the Right Thing to happen. Defined objects of type fmtflags are:

- boolalpha
- dec
- fixed
- hex
- internal
- left
- oct
- right
- scientific
- showbase
- showpoint
- showpos
- skipws
- unitbuf
- uppercase
- adjustfield
- basefield
- floatfield

Definition at line 346 of file ios_base.h.

Referenced by std::num_get< _CharT, _InIter >::do_get(), std::num_put< _CharT, _OutIter >::do_put(), std::num_put< _CharT, _OutIter >::do_put(), flags(), std::__detail::operator>>(), register_callback(), std::resetiosflags(), setf(), setf(), std::setiosflags(), and unsetf().