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