exception

Go to the documentation of this file.
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
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 2, 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 // You should have received a copy of the GNU General Public License
00020 // along with GCC; see the file COPYING.  If not, write to
00021 // the Free Software Foundation, 51 Franklin Street, Fifth Floor,
00022 // Boston, MA 02110-1301, USA.
00023 
00024 // As a special exception, you may use this file as part of a free software
00025 // library without restriction.  Specifically, if other files instantiate
00026 // templates or use macros or inline functions from this file, or you compile
00027 // this file and link it with other files to produce an executable, this
00028 // file does not by itself cause the resulting executable to be covered by
00029 // the GNU General Public License.  This exception does not however
00030 // invalidate any other reasons why the executable file might be covered by
00031 // the GNU General Public License.
00032 
00033 /** @file exception
00034  *  This is a Standard C++ Library header.
00035  */
00036 
00037 #ifndef __EXCEPTION__
00038 #define __EXCEPTION__
00039 
00040 #pragma GCC visibility push(default)
00041 
00042 #include <bits/c++config.h>
00043 
00044 extern "C++" {
00045 
00046 namespace std 
00047 {
00048   /**
00049    *  @brief Base class for all library exceptions.
00050    *
00051    *  This is the base class for all exceptions thrown by the standard
00052    *  library, and by certain language expressions.  You are free to derive
00053    *  your own %exception classes, or use a different hierarchy, or to
00054    *  throw non-class data (e.g., fundamental types).
00055    */
00056   class exception 
00057   {
00058   public:
00059     exception() throw() { }
00060     virtual ~exception() throw();
00061 
00062     /** Returns a C-style character string describing the general cause
00063      *  of the current error.  */
00064     virtual const char* what() const throw();
00065   };
00066 
00067   /** If an %exception is thrown which is not listed in a function's
00068    *  %exception specification, one of these may be thrown.  */
00069   class bad_exception : public exception 
00070   {
00071   public:
00072     bad_exception() throw() { }
00073 
00074     // This declaration is not useless:
00075     // http://gcc.gnu.org/onlinedocs/gcc-3.0.2/gcc_6.html#SEC118
00076     virtual ~bad_exception() throw();
00077 
00078     // See comment in eh_exception.cc.
00079     virtual const char* what() const throw();
00080   };
00081 
00082   /// If you write a replacement %terminate handler, it must be of this type.
00083   typedef void (*terminate_handler) ();
00084 
00085   /// If you write a replacement %unexpected handler, it must be of this type.
00086   typedef void (*unexpected_handler) ();
00087 
00088   /// Takes a new handler function as an argument, returns the old function.
00089   terminate_handler set_terminate(terminate_handler) throw();
00090 
00091   /** The runtime will call this function if %exception handling must be
00092    *  abandoned for any reason.  It can also be called by the user.  */
00093   void terminate() __attribute__ ((__noreturn__));
00094 
00095   /// Takes a new handler function as an argument, returns the old function.
00096   unexpected_handler set_unexpected(unexpected_handler) throw();
00097 
00098   /** The runtime will call this function if an %exception is thrown which
00099    *  violates the function's %exception specification.  */
00100   void unexpected() __attribute__ ((__noreturn__));
00101 
00102   /** [18.6.4]/1:  "Returns true after completing evaluation of a
00103    *  throw-expression until either completing initialization of the
00104    *  exception-declaration in the matching handler or entering @c unexpected()
00105    *  due to the throw; or after entering @c terminate() for any reason
00106    *  other than an explicit call to @c terminate().  [Note: This includes
00107    *  stack unwinding [15.2].  end note]"
00108    *
00109    *  2:  "When @c uncaught_exception() is true, throwing an %exception can
00110    *  result in a call of @c terminate() (15.5.1)."
00111    */
00112   bool uncaught_exception() throw();
00113 } // namespace std
00114 
00115 _GLIBCXX_BEGIN_NAMESPACE(__gnu_cxx)
00116 
00117   /** A replacement for the standard terminate_handler which prints more
00118       information about the terminating exception (if any) on stderr.  Call
00119       @code
00120         std::set_terminate (__gnu_cxx::__verbose_terminate_handler)
00121       @endcode
00122       to use.  For more info, see
00123       http://gcc.gnu.org/onlinedocs/libstdc++/19_diagnostics/howto.html#4
00124 
00125       In 3.4 and later, this is on by default.
00126   */
00127   void __verbose_terminate_handler ();
00128 
00129 _GLIBCXX_END_NAMESPACE
00130   
00131 } // extern "C++"
00132 
00133 #pragma GCC visibility pop
00134 
00135 #endif

Generated on Thu Nov 1 13:11:29 2007 for libstdc++ by  doxygen 1.5.1