libstdc++
exception
Go to the documentation of this file.
00001 // Exception Handling support header for -*- C++ -*-
00002 
00003 // Copyright (C) 1995-2018 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/exception.h>
00039 
00040 extern "C++" {
00041 
00042 namespace std
00043 {
00044   /** If an %exception is thrown which is not listed in a function's
00045    *  %exception specification, one of these may be thrown.  */
00046   class bad_exception : public exception
00047   {
00048   public:
00049     bad_exception() _GLIBCXX_USE_NOEXCEPT { }
00050 
00051     // This declaration is not useless:
00052     // http://gcc.gnu.org/onlinedocs/gcc-3.0.2/gcc_6.html#SEC118
00053     virtual ~bad_exception() _GLIBCXX_TXN_SAFE_DYN _GLIBCXX_USE_NOEXCEPT;
00054 
00055     // See comment in eh_exception.cc.
00056     virtual const char*
00057     what() const _GLIBCXX_TXN_SAFE_DYN _GLIBCXX_USE_NOEXCEPT;
00058   };
00059 
00060   /// If you write a replacement %terminate handler, it must be of this type.
00061   typedef void (*terminate_handler) ();
00062 
00063   /// If you write a replacement %unexpected handler, it must be of this type.
00064   typedef void (*unexpected_handler) ();
00065 
00066   /// Takes a new handler function as an argument, returns the old function.
00067   terminate_handler set_terminate(terminate_handler) _GLIBCXX_USE_NOEXCEPT;
00068 
00069 #if __cplusplus >= 201103L
00070   /// Return the current terminate handler.
00071   terminate_handler get_terminate() noexcept;
00072 #endif
00073 
00074   /** The runtime will call this function if %exception handling must be
00075    *  abandoned for any reason.  It can also be called by the user.  */
00076   void terminate() _GLIBCXX_USE_NOEXCEPT __attribute__ ((__noreturn__));
00077 
00078   /// Takes a new handler function as an argument, returns the old function.
00079   unexpected_handler set_unexpected(unexpected_handler) _GLIBCXX_USE_NOEXCEPT;
00080 
00081 #if __cplusplus >= 201103L
00082   /// Return the current unexpected handler.
00083   unexpected_handler get_unexpected() noexcept;
00084 #endif
00085 
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
00098    *  %exception can result in a call of @c terminate()
00099    *  (15.5.1).'
00100    */
00101   _GLIBCXX17_DEPRECATED
00102   bool uncaught_exception() _GLIBCXX_USE_NOEXCEPT __attribute__ ((__pure__));
00103 
00104 #if __cplusplus > 201402L || !defined(__STRICT_ANSI__) // c++17 or gnu++98
00105 #define __cpp_lib_uncaught_exceptions 201411
00106   /// The number of uncaught exceptions.
00107   int uncaught_exceptions() _GLIBCXX_USE_NOEXCEPT __attribute__ ((__pure__));
00108 #endif
00109 
00110   // @} group exceptions
00111 } // namespace std
00112 
00113 namespace __gnu_cxx
00114 {
00115 _GLIBCXX_BEGIN_NAMESPACE_VERSION
00116 
00117   /**
00118    *  @brief A replacement for the standard terminate_handler which
00119    *  prints more information about the terminating exception (if any)
00120    *  on stderr.
00121    *
00122    *  @ingroup exceptions
00123    *
00124    *  Call
00125    *   @code
00126    *     std::set_terminate(__gnu_cxx::__verbose_terminate_handler)
00127    *   @endcode
00128    *  to use.  For more info, see
00129    *  http://gcc.gnu.org/onlinedocs/libstdc++/manual/bk01pt02ch06s02.html
00130    *
00131    *  In 3.4 and later, this is on by default.
00132    */
00133   void __verbose_terminate_handler();
00134 
00135 _GLIBCXX_END_NAMESPACE_VERSION
00136 } // namespace
00137 
00138 } // extern "C++"
00139 
00140 #pragma GCC visibility pop
00141 
00142 #if (__cplusplus >= 201103L)
00143 #include <bits/exception_ptr.h>
00144 #include <bits/nested_exception.h>
00145 #endif
00146 
00147 #endif