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