xref: /openbsd-src/gnu/gcc/libstdc++-v3/libsupc++/exception (revision 404b540a9034ac75a6199ad1a32d1bbc7a0d4210)
1*404b540aSrobert// Exception Handling support header for -*- C++ -*-
2*404b540aSrobert
3*404b540aSrobert// Copyright (C) 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003,
4*404b540aSrobert// 2004, 2005, 2006, 2007
5*404b540aSrobert// Free Software Foundation
6*404b540aSrobert//
7*404b540aSrobert// This file is part of GCC.
8*404b540aSrobert//
9*404b540aSrobert// GCC is free software; you can redistribute it and/or modify
10*404b540aSrobert// it under the terms of the GNU General Public License as published by
11*404b540aSrobert// the Free Software Foundation; either version 2, or (at your option)
12*404b540aSrobert// any later version.
13*404b540aSrobert//
14*404b540aSrobert// GCC is distributed in the hope that it will be useful,
15*404b540aSrobert// but WITHOUT ANY WARRANTY; without even the implied warranty of
16*404b540aSrobert// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17*404b540aSrobert// GNU General Public License for more details.
18*404b540aSrobert//
19*404b540aSrobert// You should have received a copy of the GNU General Public License
20*404b540aSrobert// along with GCC; see the file COPYING.  If not, write to
21*404b540aSrobert// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
22*404b540aSrobert// Boston, MA 02110-1301, USA.
23*404b540aSrobert
24*404b540aSrobert// As a special exception, you may use this file as part of a free software
25*404b540aSrobert// library without restriction.  Specifically, if other files instantiate
26*404b540aSrobert// templates or use macros or inline functions from this file, or you compile
27*404b540aSrobert// this file and link it with other files to produce an executable, this
28*404b540aSrobert// file does not by itself cause the resulting executable to be covered by
29*404b540aSrobert// the GNU General Public License.  This exception does not however
30*404b540aSrobert// invalidate any other reasons why the executable file might be covered by
31*404b540aSrobert// the GNU General Public License.
32*404b540aSrobert
33*404b540aSrobert/** @file exception
34*404b540aSrobert *  This is a Standard C++ Library header.
35*404b540aSrobert */
36*404b540aSrobert
37*404b540aSrobert#ifndef __EXCEPTION__
38*404b540aSrobert#define __EXCEPTION__
39*404b540aSrobert
40*404b540aSrobert#pragma GCC visibility push(default)
41*404b540aSrobert
42*404b540aSrobert#include <bits/c++config.h>
43*404b540aSrobert
44*404b540aSrobertextern "C++" {
45*404b540aSrobert
46*404b540aSrobertnamespace std
47*404b540aSrobert{
48*404b540aSrobert  /**
49*404b540aSrobert   *  @brief Base class for all library exceptions.
50*404b540aSrobert   *
51*404b540aSrobert   *  This is the base class for all exceptions thrown by the standard
52*404b540aSrobert   *  library, and by certain language expressions.  You are free to derive
53*404b540aSrobert   *  your own %exception classes, or use a different hierarchy, or to
54*404b540aSrobert   *  throw non-class data (e.g., fundamental types).
55*404b540aSrobert   */
56*404b540aSrobert  class exception
57*404b540aSrobert  {
58*404b540aSrobert  public:
59*404b540aSrobert    exception() throw() { }
60*404b540aSrobert    virtual ~exception() throw();
61*404b540aSrobert
62*404b540aSrobert    /** Returns a C-style character string describing the general cause
63*404b540aSrobert     *  of the current error.  */
64*404b540aSrobert    virtual const char* what() const throw();
65*404b540aSrobert  };
66*404b540aSrobert
67*404b540aSrobert  /** If an %exception is thrown which is not listed in a function's
68*404b540aSrobert   *  %exception specification, one of these may be thrown.  */
69*404b540aSrobert  class bad_exception : public exception
70*404b540aSrobert  {
71*404b540aSrobert  public:
72*404b540aSrobert    bad_exception() throw() { }
73*404b540aSrobert
74*404b540aSrobert    // This declaration is not useless:
75*404b540aSrobert    // http://gcc.gnu.org/onlinedocs/gcc-3.0.2/gcc_6.html#SEC118
76*404b540aSrobert    virtual ~bad_exception() throw();
77*404b540aSrobert
78*404b540aSrobert    // See comment in eh_exception.cc.
79*404b540aSrobert    virtual const char* what() const throw();
80*404b540aSrobert  };
81*404b540aSrobert
82*404b540aSrobert  /// If you write a replacement %terminate handler, it must be of this type.
83*404b540aSrobert  typedef void (*terminate_handler) ();
84*404b540aSrobert
85*404b540aSrobert  /// If you write a replacement %unexpected handler, it must be of this type.
86*404b540aSrobert  typedef void (*unexpected_handler) ();
87*404b540aSrobert
88*404b540aSrobert  /// Takes a new handler function as an argument, returns the old function.
89*404b540aSrobert  terminate_handler set_terminate(terminate_handler) throw();
90*404b540aSrobert
91*404b540aSrobert  /** The runtime will call this function if %exception handling must be
92*404b540aSrobert   *  abandoned for any reason.  It can also be called by the user.  */
93*404b540aSrobert  void terminate() __attribute__ ((__noreturn__));
94*404b540aSrobert
95*404b540aSrobert  /// Takes a new handler function as an argument, returns the old function.
96*404b540aSrobert  unexpected_handler set_unexpected(unexpected_handler) throw();
97*404b540aSrobert
98*404b540aSrobert  /** The runtime will call this function if an %exception is thrown which
99*404b540aSrobert   *  violates the function's %exception specification.  */
100*404b540aSrobert  void unexpected() __attribute__ ((__noreturn__));
101*404b540aSrobert
102*404b540aSrobert  /** [18.6.4]/1:  "Returns true after completing evaluation of a
103*404b540aSrobert   *  throw-expression until either completing initialization of the
104*404b540aSrobert   *  exception-declaration in the matching handler or entering @c unexpected()
105*404b540aSrobert   *  due to the throw; or after entering @c terminate() for any reason
106*404b540aSrobert   *  other than an explicit call to @c terminate().  [Note: This includes
107*404b540aSrobert   *  stack unwinding [15.2].  end note]"
108*404b540aSrobert   *
109*404b540aSrobert   *  2:  "When @c uncaught_exception() is true, throwing an %exception can
110*404b540aSrobert   *  result in a call of @c terminate() (15.5.1)."
111*404b540aSrobert   */
112*404b540aSrobert  bool uncaught_exception() throw();
113*404b540aSrobert} // namespace std
114*404b540aSrobert
115*404b540aSrobert_GLIBCXX_BEGIN_NAMESPACE(__gnu_cxx)
116*404b540aSrobert
117*404b540aSrobert  /** A replacement for the standard terminate_handler which prints more
118*404b540aSrobert      information about the terminating exception (if any) on stderr.  Call
119*404b540aSrobert      @code
120*404b540aSrobert        std::set_terminate (__gnu_cxx::__verbose_terminate_handler)
121*404b540aSrobert      @endcode
122*404b540aSrobert      to use.  For more info, see
123*404b540aSrobert      http://gcc.gnu.org/onlinedocs/libstdc++/19_diagnostics/howto.html#4
124*404b540aSrobert
125*404b540aSrobert      In 3.4 and later, this is on by default.
126*404b540aSrobert  */
127*404b540aSrobert  void __verbose_terminate_handler ();
128*404b540aSrobert
129*404b540aSrobert_GLIBCXX_END_NAMESPACE
130*404b540aSrobert
131*404b540aSrobert} // extern "C++"
132*404b540aSrobert
133*404b540aSrobert#pragma GCC visibility pop
134*404b540aSrobert
135*404b540aSrobert#endif
136