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