libstdc++
|
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, 2010, 2011 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 system_header 00036 00037 #pragma GCC visibility push(default) 00038 00039 #include <bits/c++config.h> 00040 00041 extern "C++" { 00042 00043 namespace std 00044 { 00045 /** 00046 * @defgroup exceptions Exceptions 00047 * @ingroup diagnostics 00048 * 00049 * Classes and functions for reporting errors via exception classes. 00050 * @{ 00051 */ 00052 00053 /** 00054 * @brief Base class for all library exceptions. 00055 * 00056 * This is the base class for all exceptions thrown by the standard 00057 * library, and by certain language expressions. You are free to derive 00058 * your own %exception classes, or use a different hierarchy, or to 00059 * throw non-class data (e.g., fundamental types). 00060 */ 00061 class exception 00062 { 00063 public: 00064 exception() throw() { } 00065 virtual ~exception() throw(); 00066 00067 /** Returns a C-style character string describing the general cause 00068 * of the current error. */ 00069 virtual const char* what() const throw(); 00070 }; 00071 00072 /** If an %exception is thrown which is not listed in a function's 00073 * %exception specification, one of these may be thrown. */ 00074 class bad_exception : public exception 00075 { 00076 public: 00077 bad_exception() throw() { } 00078 00079 // This declaration is not useless: 00080 // http://gcc.gnu.org/onlinedocs/gcc-3.0.2/gcc_6.html#SEC118 00081 virtual ~bad_exception() throw(); 00082 00083 // See comment in eh_exception.cc. 00084 virtual const char* what() const throw(); 00085 }; 00086 00087 /// If you write a replacement %terminate handler, it must be of this type. 00088 typedef void (*terminate_handler) (); 00089 00090 /// If you write a replacement %unexpected handler, it must be of this type. 00091 typedef void (*unexpected_handler) (); 00092 00093 /// Takes a new handler function as an argument, returns the old function. 00094 terminate_handler set_terminate(terminate_handler) throw(); 00095 00096 /** The runtime will call this function if %exception handling must be 00097 * abandoned for any reason. It can also be called by the user. */ 00098 void terminate() throw() __attribute__ ((__noreturn__)); 00099 00100 /// Takes a new handler function as an argument, returns the old function. 00101 unexpected_handler set_unexpected(unexpected_handler) throw(); 00102 00103 /** The runtime will call this function if an %exception is thrown which 00104 * violates the function's %exception specification. */ 00105 void unexpected() __attribute__ ((__noreturn__)); 00106 00107 /** [18.6.4]/1: 'Returns true after completing evaluation of a 00108 * throw-expression until either completing initialization of the 00109 * exception-declaration in the matching handler or entering @c unexpected() 00110 * due to the throw; or after entering @c terminate() for any reason 00111 * other than an explicit call to @c terminate(). [Note: This includes 00112 * stack unwinding [15.2]. end note]' 00113 * 00114 * 2: 'When @c uncaught_exception() is true, throwing an 00115 * %exception can result in a call of @c terminate() 00116 * (15.5.1).' 00117 */ 00118 bool uncaught_exception() throw() __attribute__ ((__pure__)); 00119 00120 // @} group exceptions 00121 } // namespace std 00122 00123 namespace __gnu_cxx 00124 { 00125 _GLIBCXX_BEGIN_NAMESPACE_VERSION 00126 00127 /** 00128 * @brief A replacement for the standard terminate_handler which 00129 * prints more information about the terminating exception (if any) 00130 * on stderr. 00131 * 00132 * @ingroup exceptions 00133 * 00134 * Call 00135 * @code 00136 * std::set_terminate(__gnu_cxx::__verbose_terminate_handler) 00137 * @endcode 00138 * to use. For more info, see 00139 * http://gcc.gnu.org/onlinedocs/libstdc++/manual/bk01pt02ch06s02.html 00140 * 00141 * In 3.4 and later, this is on by default. 00142 */ 00143 void __verbose_terminate_handler(); 00144 00145 _GLIBCXX_END_NAMESPACE_VERSION 00146 } // namespace 00147 00148 } // extern "C++" 00149 00150 #pragma GCC visibility pop 00151 00152 #if (defined(__GXX_EXPERIMENTAL_CXX0X__) \ 00153 && defined(_GLIBCXX_ATOMIC_BUILTINS_4)) 00154 #include <bits/exception_ptr.h> 00155 #include <bits/nested_exception.h> 00156 #endif 00157 00158 #endif