1*38fd1498Szrj// Exception Handling support header for -*- C++ -*-
2*38fd1498Szrj
3*38fd1498Szrj// Copyright (C) 1995-2018 Free Software Foundation, Inc.
4*38fd1498Szrj//
5*38fd1498Szrj// This file is part of GCC.
6*38fd1498Szrj//
7*38fd1498Szrj// GCC is free software; you can redistribute it and/or modify
8*38fd1498Szrj// it under the terms of the GNU General Public License as published by
9*38fd1498Szrj// the Free Software Foundation; either version 3, or (at your option)
10*38fd1498Szrj// any later version.
11*38fd1498Szrj//
12*38fd1498Szrj// GCC is distributed in the hope that it will be useful,
13*38fd1498Szrj// but WITHOUT ANY WARRANTY; without even the implied warranty of
14*38fd1498Szrj// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15*38fd1498Szrj// GNU General Public License for more details.
16*38fd1498Szrj//
17*38fd1498Szrj// Under Section 7 of GPL version 3, you are granted additional
18*38fd1498Szrj// permissions described in the GCC Runtime Library Exception, version
19*38fd1498Szrj// 3.1, as published by the Free Software Foundation.
20*38fd1498Szrj
21*38fd1498Szrj// You should have received a copy of the GNU General Public License and
22*38fd1498Szrj// a copy of the GCC Runtime Library Exception along with this program;
23*38fd1498Szrj// see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
24*38fd1498Szrj// <http://www.gnu.org/licenses/>.
25*38fd1498Szrj
26*38fd1498Szrj/** @file exception
27*38fd1498Szrj *  This is a Standard C++ Library header.
28*38fd1498Szrj */
29*38fd1498Szrj
30*38fd1498Szrj#ifndef __EXCEPTION__
31*38fd1498Szrj#define __EXCEPTION__
32*38fd1498Szrj
33*38fd1498Szrj#pragma GCC system_header
34*38fd1498Szrj
35*38fd1498Szrj#pragma GCC visibility push(default)
36*38fd1498Szrj
37*38fd1498Szrj#include <bits/c++config.h>
38*38fd1498Szrj#include <bits/exception.h>
39*38fd1498Szrj
40*38fd1498Szrjextern "C++" {
41*38fd1498Szrj
42*38fd1498Szrjnamespace std
43*38fd1498Szrj{
44*38fd1498Szrj  /** If an %exception is thrown which is not listed in a function's
45*38fd1498Szrj   *  %exception specification, one of these may be thrown.  */
46*38fd1498Szrj  class bad_exception : public exception
47*38fd1498Szrj  {
48*38fd1498Szrj  public:
49*38fd1498Szrj    bad_exception() _GLIBCXX_USE_NOEXCEPT { }
50*38fd1498Szrj
51*38fd1498Szrj    // This declaration is not useless:
52*38fd1498Szrj    // http://gcc.gnu.org/onlinedocs/gcc-3.0.2/gcc_6.html#SEC118
53*38fd1498Szrj    virtual ~bad_exception() _GLIBCXX_TXN_SAFE_DYN _GLIBCXX_USE_NOEXCEPT;
54*38fd1498Szrj
55*38fd1498Szrj    // See comment in eh_exception.cc.
56*38fd1498Szrj    virtual const char*
57*38fd1498Szrj    what() const _GLIBCXX_TXN_SAFE_DYN _GLIBCXX_USE_NOEXCEPT;
58*38fd1498Szrj  };
59*38fd1498Szrj
60*38fd1498Szrj  /// If you write a replacement %terminate handler, it must be of this type.
61*38fd1498Szrj  typedef void (*terminate_handler) ();
62*38fd1498Szrj
63*38fd1498Szrj  /// If you write a replacement %unexpected handler, it must be of this type.
64*38fd1498Szrj  typedef void (*unexpected_handler) ();
65*38fd1498Szrj
66*38fd1498Szrj  /// Takes a new handler function as an argument, returns the old function.
67*38fd1498Szrj  terminate_handler set_terminate(terminate_handler) _GLIBCXX_USE_NOEXCEPT;
68*38fd1498Szrj
69*38fd1498Szrj#if __cplusplus >= 201103L
70*38fd1498Szrj  /// Return the current terminate handler.
71*38fd1498Szrj  terminate_handler get_terminate() noexcept;
72*38fd1498Szrj#endif
73*38fd1498Szrj
74*38fd1498Szrj  /** The runtime will call this function if %exception handling must be
75*38fd1498Szrj   *  abandoned for any reason.  It can also be called by the user.  */
76*38fd1498Szrj  void terminate() _GLIBCXX_USE_NOEXCEPT __attribute__ ((__noreturn__));
77*38fd1498Szrj
78*38fd1498Szrj  /// Takes a new handler function as an argument, returns the old function.
79*38fd1498Szrj  unexpected_handler set_unexpected(unexpected_handler) _GLIBCXX_USE_NOEXCEPT;
80*38fd1498Szrj
81*38fd1498Szrj#if __cplusplus >= 201103L
82*38fd1498Szrj  /// Return the current unexpected handler.
83*38fd1498Szrj  unexpected_handler get_unexpected() noexcept;
84*38fd1498Szrj#endif
85*38fd1498Szrj
86*38fd1498Szrj  /** The runtime will call this function if an %exception is thrown which
87*38fd1498Szrj   *  violates the function's %exception specification.  */
88*38fd1498Szrj  void unexpected() __attribute__ ((__noreturn__));
89*38fd1498Szrj
90*38fd1498Szrj  /** [18.6.4]/1:  'Returns true after completing evaluation of a
91*38fd1498Szrj   *  throw-expression until either completing initialization of the
92*38fd1498Szrj   *  exception-declaration in the matching handler or entering @c unexpected()
93*38fd1498Szrj   *  due to the throw; or after entering @c terminate() for any reason
94*38fd1498Szrj   *  other than an explicit call to @c terminate().  [Note: This includes
95*38fd1498Szrj   *  stack unwinding [15.2].  end note]'
96*38fd1498Szrj   *
97*38fd1498Szrj   *  2: 'When @c uncaught_exception() is true, throwing an
98*38fd1498Szrj   *  %exception can result in a call of @c terminate()
99*38fd1498Szrj   *  (15.5.1).'
100*38fd1498Szrj   */
101*38fd1498Szrj  _GLIBCXX17_DEPRECATED
102*38fd1498Szrj  bool uncaught_exception() _GLIBCXX_USE_NOEXCEPT __attribute__ ((__pure__));
103*38fd1498Szrj
104*38fd1498Szrj#if __cplusplus > 201402L || !defined(__STRICT_ANSI__) // c++17 or gnu++98
105*38fd1498Szrj#define __cpp_lib_uncaught_exceptions 201411
106*38fd1498Szrj  /// The number of uncaught exceptions.
107*38fd1498Szrj  int uncaught_exceptions() _GLIBCXX_USE_NOEXCEPT __attribute__ ((__pure__));
108*38fd1498Szrj#endif
109*38fd1498Szrj
110*38fd1498Szrj  // @} group exceptions
111*38fd1498Szrj} // namespace std
112*38fd1498Szrj
113*38fd1498Szrjnamespace __gnu_cxx
114*38fd1498Szrj{
115*38fd1498Szrj_GLIBCXX_BEGIN_NAMESPACE_VERSION
116*38fd1498Szrj
117*38fd1498Szrj  /**
118*38fd1498Szrj   *  @brief A replacement for the standard terminate_handler which
119*38fd1498Szrj   *  prints more information about the terminating exception (if any)
120*38fd1498Szrj   *  on stderr.
121*38fd1498Szrj   *
122*38fd1498Szrj   *  @ingroup exceptions
123*38fd1498Szrj   *
124*38fd1498Szrj   *  Call
125*38fd1498Szrj   *   @code
126*38fd1498Szrj   *     std::set_terminate(__gnu_cxx::__verbose_terminate_handler)
127*38fd1498Szrj   *   @endcode
128*38fd1498Szrj   *  to use.  For more info, see
129*38fd1498Szrj   *  http://gcc.gnu.org/onlinedocs/libstdc++/manual/bk01pt02ch06s02.html
130*38fd1498Szrj   *
131*38fd1498Szrj   *  In 3.4 and later, this is on by default.
132*38fd1498Szrj   */
133*38fd1498Szrj  void __verbose_terminate_handler();
134*38fd1498Szrj
135*38fd1498Szrj_GLIBCXX_END_NAMESPACE_VERSION
136*38fd1498Szrj} // namespace
137*38fd1498Szrj
138*38fd1498Szrj} // extern "C++"
139*38fd1498Szrj
140*38fd1498Szrj#pragma GCC visibility pop
141*38fd1498Szrj
142*38fd1498Szrj#if (__cplusplus >= 201103L)
143*38fd1498Szrj#include <bits/exception_ptr.h>
144*38fd1498Szrj#include <bits/nested_exception.h>
145*38fd1498Szrj#endif
146*38fd1498Szrj
147*38fd1498Szrj#endif
148