xref: /dflybsd-src/contrib/gcc-4.7/libstdc++-v3/libsupc++/exception (revision 04febcfb30580676d3e95f58a16c5137ee478b32)
1*e4b17023SJohn Marino// Exception Handling support header for -*- C++ -*-
2*e4b17023SJohn Marino
3*e4b17023SJohn Marino// Copyright (C) 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003,
4*e4b17023SJohn Marino// 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011
5*e4b17023SJohn Marino// Free Software Foundation
6*e4b17023SJohn Marino//
7*e4b17023SJohn Marino// This file is part of GCC.
8*e4b17023SJohn Marino//
9*e4b17023SJohn Marino// GCC is free software; you can redistribute it and/or modify
10*e4b17023SJohn Marino// it under the terms of the GNU General Public License as published by
11*e4b17023SJohn Marino// the Free Software Foundation; either version 3, or (at your option)
12*e4b17023SJohn Marino// any later version.
13*e4b17023SJohn Marino//
14*e4b17023SJohn Marino// GCC is distributed in the hope that it will be useful,
15*e4b17023SJohn Marino// but WITHOUT ANY WARRANTY; without even the implied warranty of
16*e4b17023SJohn Marino// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17*e4b17023SJohn Marino// GNU General Public License for more details.
18*e4b17023SJohn Marino//
19*e4b17023SJohn Marino// Under Section 7 of GPL version 3, you are granted additional
20*e4b17023SJohn Marino// permissions described in the GCC Runtime Library Exception, version
21*e4b17023SJohn Marino// 3.1, as published by the Free Software Foundation.
22*e4b17023SJohn Marino
23*e4b17023SJohn Marino// You should have received a copy of the GNU General Public License and
24*e4b17023SJohn Marino// a copy of the GCC Runtime Library Exception along with this program;
25*e4b17023SJohn Marino// see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
26*e4b17023SJohn Marino// <http://www.gnu.org/licenses/>.
27*e4b17023SJohn Marino
28*e4b17023SJohn Marino/** @file exception
29*e4b17023SJohn Marino *  This is a Standard C++ Library header.
30*e4b17023SJohn Marino */
31*e4b17023SJohn Marino
32*e4b17023SJohn Marino#ifndef __EXCEPTION__
33*e4b17023SJohn Marino#define __EXCEPTION__
34*e4b17023SJohn Marino
35*e4b17023SJohn Marino#pragma GCC system_header
36*e4b17023SJohn Marino
37*e4b17023SJohn Marino#pragma GCC visibility push(default)
38*e4b17023SJohn Marino
39*e4b17023SJohn Marino#include <bits/c++config.h>
40*e4b17023SJohn Marino#include <bits/atomic_lockfree_defines.h>
41*e4b17023SJohn Marino
42*e4b17023SJohn Marinoextern "C++" {
43*e4b17023SJohn Marino
44*e4b17023SJohn Marinonamespace std
45*e4b17023SJohn Marino{
46*e4b17023SJohn Marino  /**
47*e4b17023SJohn Marino   * @defgroup exceptions Exceptions
48*e4b17023SJohn Marino   * @ingroup diagnostics
49*e4b17023SJohn Marino   *
50*e4b17023SJohn Marino   * Classes and functions for reporting errors via exception classes.
51*e4b17023SJohn Marino   * @{
52*e4b17023SJohn Marino   */
53*e4b17023SJohn Marino
54*e4b17023SJohn Marino  /**
55*e4b17023SJohn Marino   *  @brief Base class for all library exceptions.
56*e4b17023SJohn Marino   *
57*e4b17023SJohn Marino   *  This is the base class for all exceptions thrown by the standard
58*e4b17023SJohn Marino   *  library, and by certain language expressions.  You are free to derive
59*e4b17023SJohn Marino   *  your own %exception classes, or use a different hierarchy, or to
60*e4b17023SJohn Marino   *  throw non-class data (e.g., fundamental types).
61*e4b17023SJohn Marino   */
62*e4b17023SJohn Marino  class exception
63*e4b17023SJohn Marino  {
64*e4b17023SJohn Marino  public:
65*e4b17023SJohn Marino    exception() _GLIBCXX_USE_NOEXCEPT { }
66*e4b17023SJohn Marino    virtual ~exception() _GLIBCXX_USE_NOEXCEPT;
67*e4b17023SJohn Marino
68*e4b17023SJohn Marino    /** Returns a C-style character string describing the general cause
69*e4b17023SJohn Marino     *  of the current error.  */
70*e4b17023SJohn Marino    virtual const char* what() const _GLIBCXX_USE_NOEXCEPT;
71*e4b17023SJohn Marino  };
72*e4b17023SJohn Marino
73*e4b17023SJohn Marino  /** If an %exception is thrown which is not listed in a function's
74*e4b17023SJohn Marino   *  %exception specification, one of these may be thrown.  */
75*e4b17023SJohn Marino  class bad_exception : public exception
76*e4b17023SJohn Marino  {
77*e4b17023SJohn Marino  public:
78*e4b17023SJohn Marino    bad_exception() _GLIBCXX_USE_NOEXCEPT { }
79*e4b17023SJohn Marino
80*e4b17023SJohn Marino    // This declaration is not useless:
81*e4b17023SJohn Marino    // http://gcc.gnu.org/onlinedocs/gcc-3.0.2/gcc_6.html#SEC118
82*e4b17023SJohn Marino    virtual ~bad_exception() _GLIBCXX_USE_NOEXCEPT;
83*e4b17023SJohn Marino
84*e4b17023SJohn Marino    // See comment in eh_exception.cc.
85*e4b17023SJohn Marino    virtual const char* what() const _GLIBCXX_USE_NOEXCEPT;
86*e4b17023SJohn Marino  };
87*e4b17023SJohn Marino
88*e4b17023SJohn Marino  /// If you write a replacement %terminate handler, it must be of this type.
89*e4b17023SJohn Marino  typedef void (*terminate_handler) ();
90*e4b17023SJohn Marino
91*e4b17023SJohn Marino  /// If you write a replacement %unexpected handler, it must be of this type.
92*e4b17023SJohn Marino  typedef void (*unexpected_handler) ();
93*e4b17023SJohn Marino
94*e4b17023SJohn Marino  /// Takes a new handler function as an argument, returns the old function.
95*e4b17023SJohn Marino  terminate_handler set_terminate(terminate_handler) _GLIBCXX_USE_NOEXCEPT;
96*e4b17023SJohn Marino
97*e4b17023SJohn Marino  /** The runtime will call this function if %exception handling must be
98*e4b17023SJohn Marino   *  abandoned for any reason.  It can also be called by the user.  */
99*e4b17023SJohn Marino  void terminate() _GLIBCXX_USE_NOEXCEPT __attribute__ ((__noreturn__));
100*e4b17023SJohn Marino
101*e4b17023SJohn Marino  /// Takes a new handler function as an argument, returns the old function.
102*e4b17023SJohn Marino  unexpected_handler set_unexpected(unexpected_handler) _GLIBCXX_USE_NOEXCEPT;
103*e4b17023SJohn Marino
104*e4b17023SJohn Marino  /** The runtime will call this function if an %exception is thrown which
105*e4b17023SJohn Marino   *  violates the function's %exception specification.  */
106*e4b17023SJohn Marino  void unexpected() __attribute__ ((__noreturn__));
107*e4b17023SJohn Marino
108*e4b17023SJohn Marino  /** [18.6.4]/1:  'Returns true after completing evaluation of a
109*e4b17023SJohn Marino   *  throw-expression until either completing initialization of the
110*e4b17023SJohn Marino   *  exception-declaration in the matching handler or entering @c unexpected()
111*e4b17023SJohn Marino   *  due to the throw; or after entering @c terminate() for any reason
112*e4b17023SJohn Marino   *  other than an explicit call to @c terminate().  [Note: This includes
113*e4b17023SJohn Marino   *  stack unwinding [15.2].  end note]'
114*e4b17023SJohn Marino   *
115*e4b17023SJohn Marino   *  2: 'When @c uncaught_exception() is true, throwing an
116*e4b17023SJohn Marino   *  %exception can result in a call of @c terminate()
117*e4b17023SJohn Marino   *  (15.5.1).'
118*e4b17023SJohn Marino   */
119*e4b17023SJohn Marino  bool uncaught_exception() _GLIBCXX_USE_NOEXCEPT __attribute__ ((__pure__));
120*e4b17023SJohn Marino
121*e4b17023SJohn Marino  // @} group exceptions
122*e4b17023SJohn Marino} // namespace std
123*e4b17023SJohn Marino
124*e4b17023SJohn Marinonamespace __gnu_cxx
125*e4b17023SJohn Marino{
126*e4b17023SJohn Marino_GLIBCXX_BEGIN_NAMESPACE_VERSION
127*e4b17023SJohn Marino
128*e4b17023SJohn Marino  /**
129*e4b17023SJohn Marino   *  @brief A replacement for the standard terminate_handler which
130*e4b17023SJohn Marino   *  prints more information about the terminating exception (if any)
131*e4b17023SJohn Marino   *  on stderr.
132*e4b17023SJohn Marino   *
133*e4b17023SJohn Marino   *  @ingroup exceptions
134*e4b17023SJohn Marino   *
135*e4b17023SJohn Marino   *  Call
136*e4b17023SJohn Marino   *   @code
137*e4b17023SJohn Marino   *     std::set_terminate(__gnu_cxx::__verbose_terminate_handler)
138*e4b17023SJohn Marino   *   @endcode
139*e4b17023SJohn Marino   *  to use.  For more info, see
140*e4b17023SJohn Marino   *  http://gcc.gnu.org/onlinedocs/libstdc++/manual/bk01pt02ch06s02.html
141*e4b17023SJohn Marino   *
142*e4b17023SJohn Marino   *  In 3.4 and later, this is on by default.
143*e4b17023SJohn Marino   */
144*e4b17023SJohn Marino  void __verbose_terminate_handler();
145*e4b17023SJohn Marino
146*e4b17023SJohn Marino_GLIBCXX_END_NAMESPACE_VERSION
147*e4b17023SJohn Marino} // namespace
148*e4b17023SJohn Marino
149*e4b17023SJohn Marino} // extern "C++"
150*e4b17023SJohn Marino
151*e4b17023SJohn Marino#pragma GCC visibility pop
152*e4b17023SJohn Marino
153*e4b17023SJohn Marino#if defined(__GXX_EXPERIMENTAL_CXX0X__) && (ATOMIC_INT_LOCK_FREE > 1)
154*e4b17023SJohn Marino#include <bits/exception_ptr.h>
155*e4b17023SJohn Marino#include <bits/nested_exception.h>
156*e4b17023SJohn Marino#endif
157*e4b17023SJohn Marino
158*e4b17023SJohn Marino#endif
159