00001 // Exception Handling support header for -*- C++ -*- 00002 00003 // Copyright (C) 1995, 1996, 1997, 1998, 2000, 2001, 2002 00004 // Free Software Foundation 00005 // 00006 // This file is part of GCC. 00007 // 00008 // GCC is free software; you can redistribute it and/or modify 00009 // it under the terms of the GNU General Public License as published by 00010 // the Free Software Foundation; either version 2, or (at your option) 00011 // any later version. 00012 // 00013 // GCC is distributed in the hope that it will be useful, 00014 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00015 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00016 // GNU General Public License for more details. 00017 // 00018 // You should have received a copy of the GNU General Public License 00019 // along with GCC; see the file COPYING. If not, write to 00020 // the Free Software Foundation, 59 Temple Place - Suite 330, 00021 // Boston, MA 02111-1307, USA. 00022 00023 // As a special exception, you may use this file as part of a free software 00024 // library without restriction. Specifically, if other files instantiate 00025 // templates or use macros or inline functions from this file, or you compile 00026 // this file and link it with other files to produce an executable, this 00027 // file does not by itself cause the resulting executable to be covered by 00028 // the GNU General Public License. This exception does not however 00029 // invalidate any other reasons why the executable file might be covered by 00030 // the GNU General Public License. 00031 00032 /** @file exception 00033 * This header defines several types and functions relating to the 00034 * handling of exceptions in a C++ program. 00035 */ 00036 00037 #ifndef __EXCEPTION__ 00038 #define __EXCEPTION__ 00039 00040 extern "C++" { 00041 00042 namespace std 00043 { 00044 /** 00045 * @brief Base class for all library exceptions. 00046 * 00047 * This is the base class for all exceptions thrown by the standard 00048 * library, and by certain language expressions. You are free to derive 00049 * your own %exception classes, or use a different hierarchy, or to 00050 * throw non-class data (e.g., fundamental types). 00051 */ 00052 class exception 00053 { 00054 public: 00055 exception() throw() { } 00056 virtual ~exception() throw(); 00057 /** Returns a C-style character string describing the general cause 00058 * of the current error. */ 00059 virtual const char* what() const throw(); 00060 }; 00061 00062 /** If an %exception is thrown which is not listed in a function's 00063 * %exception specification, one of these may be thrown. */ 00064 class bad_exception : public exception 00065 { 00066 public: 00067 bad_exception() throw() { } 00068 // This declaration is not useless: 00069 // http://gcc.gnu.org/onlinedocs/gcc-3.0.2/gcc_6.html#SEC118 00070 virtual ~bad_exception() throw(); 00071 }; 00072 00073 /// If you write a replacement %terminate handler, it must be of this type. 00074 typedef void (*terminate_handler) (); 00075 /// If you write a replacement %unexpected handler, it must be of this type. 00076 typedef void (*unexpected_handler) (); 00077 00078 /// Takes a new handler function as an argument, returns the old function. 00079 terminate_handler set_terminate(terminate_handler) throw(); 00080 /** The runtime will call this function if %exception handling must be 00081 * abandoned for any reason. It can also be called by the user. */ 00082 void terminate() __attribute__ ((__noreturn__)); 00083 00084 /// Takes a new handler function as an argument, returns the old function. 00085 unexpected_handler set_unexpected(unexpected_handler) throw(); 00086 /** The runtime will call this function if an %exception is thrown which 00087 * violates the function's %exception specification. */ 00088 void unexpected() __attribute__ ((__noreturn__)); 00089 00090 /** [18.6.4]/1: "Returns true after completing evaluation of a 00091 * throw-expression until either completing initialization of the 00092 * exception-declaration in the matching handler or entering @c unexpected() 00093 * due to the throw; or after entering @c terminate() for any reason 00094 * other than an explicit call to @c terminate(). [Note: This includes 00095 * stack unwinding [15.2]. end note]" 00096 * 00097 * 2: "When @c uncaught_exception() is true, throwing an %exception can 00098 * result in a call of @c terminate() (15.5.1)." 00099 */ 00100 bool uncaught_exception() throw(); 00101 } // namespace std 00102 00103 namespace __gnu_cxx 00104 { 00105 /** A replacement for the standard terminate_handler which prints more 00106 information about the terminating exception (if any) on stderr. Call 00107 @code 00108 std::set_terminate (__gnu_cxx::__verbose_terminate_handler) 00109 @endcode 00110 to use. For more info, see 00111 http://gcc.gnu.org/onlinedocs/libstdc++/19_diagnostics/howto.html#4 00112 00113 In 3.4 and later, this is on by default. 00114 */ 00115 void __verbose_terminate_handler (); 00116 } // namespace __gnu_cxx 00117 00118 } // extern "C++" 00119 00120 #endif