libstdc++
|
00001 // Exception Handling support header for -*- C++ -*- 00002 00003 // Copyright (C) 1995-2016 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_TXN_SAFE_DYN _GLIBCXX_USE_NOEXCEPT; 00065 00066 /** Returns a C-style character string describing the general cause 00067 * of the current error. */ 00068 virtual const char* 00069 what() const _GLIBCXX_TXN_SAFE_DYN _GLIBCXX_USE_NOEXCEPT; 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() _GLIBCXX_USE_NOEXCEPT { } 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() _GLIBCXX_TXN_SAFE_DYN _GLIBCXX_USE_NOEXCEPT; 00082 00083 // See comment in eh_exception.cc. 00084 virtual const char* 00085 what() const _GLIBCXX_TXN_SAFE_DYN _GLIBCXX_USE_NOEXCEPT; 00086 }; 00087 00088 /// If you write a replacement %terminate handler, it must be of this type. 00089 typedef void (*terminate_handler) (); 00090 00091 /// If you write a replacement %unexpected handler, it must be of this type. 00092 typedef void (*unexpected_handler) (); 00093 00094 /// Takes a new handler function as an argument, returns the old function. 00095 terminate_handler set_terminate(terminate_handler) _GLIBCXX_USE_NOEXCEPT; 00096 00097 #if __cplusplus >= 201103L 00098 /// Return the current terminate handler. 00099 terminate_handler get_terminate() noexcept; 00100 #endif 00101 00102 /** The runtime will call this function if %exception handling must be 00103 * abandoned for any reason. It can also be called by the user. */ 00104 void terminate() _GLIBCXX_USE_NOEXCEPT __attribute__ ((__noreturn__)); 00105 00106 /// Takes a new handler function as an argument, returns the old function. 00107 unexpected_handler set_unexpected(unexpected_handler) _GLIBCXX_USE_NOEXCEPT; 00108 00109 #if __cplusplus >= 201103L 00110 /// Return the current unexpected handler. 00111 unexpected_handler get_unexpected() noexcept; 00112 #endif 00113 00114 /** The runtime will call this function if an %exception is thrown which 00115 * violates the function's %exception specification. */ 00116 void unexpected() __attribute__ ((__noreturn__)); 00117 00118 /** [18.6.4]/1: 'Returns true after completing evaluation of a 00119 * throw-expression until either completing initialization of the 00120 * exception-declaration in the matching handler or entering @c unexpected() 00121 * due to the throw; or after entering @c terminate() for any reason 00122 * other than an explicit call to @c terminate(). [Note: This includes 00123 * stack unwinding [15.2]. end note]' 00124 * 00125 * 2: 'When @c uncaught_exception() is true, throwing an 00126 * %exception can result in a call of @c terminate() 00127 * (15.5.1).' 00128 */ 00129 bool uncaught_exception() _GLIBCXX_USE_NOEXCEPT __attribute__ ((__pure__)); 00130 00131 #if __cplusplus > 201402L || !defined(__STRICT_ANSI__) // c++1z or gnu++98 00132 #define __cpp_lib_uncaught_exceptions 201411 00133 /// The number of uncaught exceptions. 00134 int uncaught_exceptions() _GLIBCXX_USE_NOEXCEPT __attribute__ ((__pure__)); 00135 #endif 00136 00137 // @} group exceptions 00138 } // namespace std 00139 00140 namespace __gnu_cxx 00141 { 00142 _GLIBCXX_BEGIN_NAMESPACE_VERSION 00143 00144 /** 00145 * @brief A replacement for the standard terminate_handler which 00146 * prints more information about the terminating exception (if any) 00147 * on stderr. 00148 * 00149 * @ingroup exceptions 00150 * 00151 * Call 00152 * @code 00153 * std::set_terminate(__gnu_cxx::__verbose_terminate_handler) 00154 * @endcode 00155 * to use. For more info, see 00156 * http://gcc.gnu.org/onlinedocs/libstdc++/manual/bk01pt02ch06s02.html 00157 * 00158 * In 3.4 and later, this is on by default. 00159 */ 00160 void __verbose_terminate_handler(); 00161 00162 _GLIBCXX_END_NAMESPACE_VERSION 00163 } // namespace 00164 00165 } // extern "C++" 00166 00167 #pragma GCC visibility pop 00168 00169 #if (__cplusplus >= 201103L) && (ATOMIC_INT_LOCK_FREE > 1) 00170 #include <bits/exception_ptr.h> 00171 #include <bits/nested_exception.h> 00172 #endif 00173 00174 #endif