00001 // Exception Handling support header for -*- C++ -*- 00002 00003 // Copyright (C) 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 00004 // 2004, 2005, 2006, 2007, 2008, 2009 00005 // Free Software Foundation 00006 // 00007 // This file is part of GCC. 00008 // 00009 // GCC is free software; you can redistribute it and/or modify 00010 // it under the terms of the GNU General Public License as published by 00011 // the Free Software Foundation; either version 3, or (at your option) 00012 // any later version. 00013 // 00014 // GCC is distributed in the hope that it will be useful, 00015 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00016 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00017 // GNU General Public License for more details. 00018 // 00019 // Under Section 7 of GPL version 3, you are granted additional 00020 // permissions described in the GCC Runtime Library Exception, version 00021 // 3.1, as published by the Free Software Foundation. 00022 00023 // You should have received a copy of the GNU General Public License and 00024 // a copy of the GCC Runtime Library Exception along with this program; 00025 // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see 00026 // <http://www.gnu.org/licenses/>. 00027 00028 /** @file exception 00029 * This is a Standard C++ Library header. 00030 */ 00031 00032 #ifndef __EXCEPTION__ 00033 #define __EXCEPTION__ 00034 00035 #pragma GCC visibility push(default) 00036 00037 #include <bits/c++config.h> 00038 00039 extern "C++" { 00040 00041 namespace std 00042 { 00043 /** 00044 * @defgroup exceptions Exceptions 00045 * @ingroup diagnostics 00046 * 00047 * Classes and functions for reporting errors via exception classes. 00048 * @{ 00049 */ 00050 00051 /** 00052 * @brief Base class for all library exceptions. 00053 * 00054 * This is the base class for all exceptions thrown by the standard 00055 * library, and by certain language expressions. You are free to derive 00056 * your own %exception classes, or use a different hierarchy, or to 00057 * throw non-class data (e.g., fundamental types). 00058 */ 00059 class exception 00060 { 00061 public: 00062 exception() throw() { } 00063 virtual ~exception() throw(); 00064 00065 /** Returns a C-style character string describing the general cause 00066 * of the current error. */ 00067 virtual const char* what() const throw(); 00068 }; 00069 00070 /** If an %exception is thrown which is not listed in a function's 00071 * %exception specification, one of these may be thrown. */ 00072 class bad_exception : public exception 00073 { 00074 public: 00075 bad_exception() throw() { } 00076 00077 // This declaration is not useless: 00078 // http://gcc.gnu.org/onlinedocs/gcc-3.0.2/gcc_6.html#SEC118 00079 virtual ~bad_exception() throw(); 00080 00081 // See comment in eh_exception.cc. 00082 virtual const char* what() const throw(); 00083 }; 00084 00085 /// If you write a replacement %terminate handler, it must be of this type. 00086 typedef void (*terminate_handler) (); 00087 00088 /// If you write a replacement %unexpected handler, it must be of this type. 00089 typedef void (*unexpected_handler) (); 00090 00091 /// Takes a new handler function as an argument, returns the old function. 00092 terminate_handler set_terminate(terminate_handler) throw(); 00093 00094 /** The runtime will call this function if %exception handling must be 00095 * abandoned for any reason. It can also be called by the user. */ 00096 void terminate() __attribute__ ((__noreturn__)); 00097 00098 /// Takes a new handler function as an argument, returns the old function. 00099 unexpected_handler set_unexpected(unexpected_handler) throw(); 00100 00101 /** The runtime will call this function if an %exception is thrown which 00102 * violates the function's %exception specification. */ 00103 void unexpected() __attribute__ ((__noreturn__)); 00104 00105 /** [18.6.4]/1: "Returns true after completing evaluation of a 00106 * throw-expression until either completing initialization of the 00107 * exception-declaration in the matching handler or entering @c unexpected() 00108 * due to the throw; or after entering @c terminate() for any reason 00109 * other than an explicit call to @c terminate(). [Note: This includes 00110 * stack unwinding [15.2]. end note]" 00111 * 00112 * 2: "When @c uncaught_exception() is true, throwing an %exception can 00113 * result in a call of @c terminate() (15.5.1)." 00114 */ 00115 bool uncaught_exception() throw(); 00116 00117 // @} group exceptions 00118 } // namespace std 00119 00120 _GLIBCXX_BEGIN_NAMESPACE(__gnu_cxx) 00121 00122 /** 00123 * @brief A replacement for the standard terminate_handler which 00124 * prints more information about the terminating exception (if any) 00125 * on stderr. 00126 * 00127 * @ingroup exceptions 00128 * 00129 * Call 00130 * @code 00131 * std::set_terminate(__gnu_cxx::__verbose_terminate_handler) 00132 * @endcode 00133 * to use. For more info, see 00134 * http://gcc.gnu.org/onlinedocs/libstdc++/manual/bk01pt02ch06s02.html 00135 * 00136 * In 3.4 and later, this is on by default. 00137 */ 00138 void __verbose_terminate_handler(); 00139 00140 _GLIBCXX_END_NAMESPACE 00141 00142 } // extern "C++" 00143 00144 #pragma GCC visibility pop 00145 00146 #if (defined(__GXX_EXPERIMENTAL_CXX0X__) \ 00147 && defined(_GLIBCXX_ATOMIC_BUILTINS_4)) 00148 #include <exception_ptr.h> 00149 #endif 00150 00151 #endif