exception

Go to the documentation of this file.
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, 51 Franklin Street, Fifth Floor,
00021 // Boston, MA 02110-1301, 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 #pragma GCC visibility push(default)
00041 
00042 extern "C++" {
00043 
00044 namespace std 
00045 {
00046   /**
00047    *  @brief Base class for all library exceptions.
00048    *
00049    *  This is the base class for all exceptions thrown by the standard
00050    *  library, and by certain language expressions.  You are free to derive
00051    *  your own %exception classes, or use a different hierarchy, or to
00052    *  throw non-class data (e.g., fundamental types).
00053    */
00054   class exception 
00055   {
00056   public:
00057     exception() throw() { }
00058     virtual ~exception() throw();
00059     /** Returns a C-style character string describing the general cause
00060      *  of the current error.  */
00061     virtual const char* what() const throw();
00062   };
00063 
00064   /** If an %exception is thrown which is not listed in a function's
00065    *  %exception specification, one of these may be thrown.  */
00066   class bad_exception : public exception 
00067   {
00068   public:
00069     bad_exception() throw() { }
00070     // This declaration is not useless:
00071     // http://gcc.gnu.org/onlinedocs/gcc-3.0.2/gcc_6.html#SEC118
00072     virtual ~bad_exception() throw();
00073   };
00074 
00075   /// If you write a replacement %terminate handler, it must be of this type.
00076   typedef void (*terminate_handler) ();
00077   /// If you write a replacement %unexpected handler, it must be of this type.
00078   typedef void (*unexpected_handler) ();
00079 
00080   /// Takes a new handler function as an argument, returns the old function.
00081   terminate_handler set_terminate(terminate_handler) throw();
00082   /** The runtime will call this function if %exception handling must be
00083    *  abandoned for any reason.  It can also be called by the user.  */
00084   void terminate() __attribute__ ((__noreturn__));
00085 
00086   /// Takes a new handler function as an argument, returns the old function.
00087   unexpected_handler set_unexpected(unexpected_handler) throw();
00088   /** The runtime will call this function if an %exception is thrown which
00089    *  violates the function's %exception specification.  */
00090   void unexpected() __attribute__ ((__noreturn__));
00091 
00092   /** [18.6.4]/1:  "Returns true after completing evaluation of a
00093    *  throw-expression until either completing initialization of the
00094    *  exception-declaration in the matching handler or entering @c unexpected()
00095    *  due to the throw; or after entering @c terminate() for any reason
00096    *  other than an explicit call to @c terminate().  [Note: This includes
00097    *  stack unwinding [15.2].  end note]"
00098    *
00099    *  2:  "When @c uncaught_exception() is true, throwing an %exception can
00100    *  result in a call of @c terminate() (15.5.1)."
00101    */
00102   bool uncaught_exception() throw();
00103 } // namespace std
00104 
00105 namespace __gnu_cxx
00106 {
00107   /** A replacement for the standard terminate_handler which prints more
00108       information about the terminating exception (if any) on stderr.  Call
00109       @code
00110         std::set_terminate (__gnu_cxx::__verbose_terminate_handler)
00111       @endcode
00112       to use.  For more info, see
00113       http://gcc.gnu.org/onlinedocs/libstdc++/19_diagnostics/howto.html#4
00114 
00115       In 3.4 and later, this is on by default.
00116   */
00117   void __verbose_terminate_handler ();
00118 } // namespace __gnu_cxx
00119   
00120 } // extern "C++"
00121 
00122 #pragma GCC visibility pop
00123 
00124 #endif

Generated on Tue Dec 2 03:59:24 2008 for libstdc++ by  doxygen 1.5.7.1