197403Sobrien// Exception Handling support header for -*- C++ -*-
297403Sobrien
3169691Skan// Copyright (C) 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003,
4169691Skan// 2004, 2005, 2006, 2007
597403Sobrien// Free Software Foundation
697403Sobrien//
7132720Skan// This file is part of GCC.
897403Sobrien//
9132720Skan// GCC is free software; you can redistribute it and/or modify
1097403Sobrien// it under the terms of the GNU General Public License as published by
1197403Sobrien// the Free Software Foundation; either version 2, or (at your option)
1297403Sobrien// any later version.
1397403Sobrien// 
14132720Skan// GCC is distributed in the hope that it will be useful,
1597403Sobrien// but WITHOUT ANY WARRANTY; without even the implied warranty of
1697403Sobrien// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
1797403Sobrien// GNU General Public License for more details.
1897403Sobrien// 
1997403Sobrien// You should have received a copy of the GNU General Public License
20132720Skan// along with GCC; see the file COPYING.  If not, write to
21169691Skan// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
22169691Skan// Boston, MA 02110-1301, USA.
2397403Sobrien
2497403Sobrien// As a special exception, you may use this file as part of a free software
2597403Sobrien// library without restriction.  Specifically, if other files instantiate
2697403Sobrien// templates or use macros or inline functions from this file, or you compile
2797403Sobrien// this file and link it with other files to produce an executable, this
2897403Sobrien// file does not by itself cause the resulting executable to be covered by
2997403Sobrien// the GNU General Public License.  This exception does not however
3097403Sobrien// invalidate any other reasons why the executable file might be covered by
3197403Sobrien// the GNU General Public License.
3297403Sobrien
3397403Sobrien/** @file exception
34169691Skan *  This is a Standard C++ Library header.
3597403Sobrien */
3697403Sobrien
3797403Sobrien#ifndef __EXCEPTION__
3897403Sobrien#define __EXCEPTION__
3997403Sobrien
40169691Skan#pragma GCC visibility push(default)
41169691Skan
42169691Skan#include <bits/c++config.h>
43169691Skan
4497403Sobrienextern "C++" {
4597403Sobrien
4697403Sobriennamespace std 
4797403Sobrien{
48117397Skan  /**
49117397Skan   *  @brief Base class for all library exceptions.
50117397Skan   *
51117397Skan   *  This is the base class for all exceptions thrown by the standard
5297403Sobrien   *  library, and by certain language expressions.  You are free to derive
5397403Sobrien   *  your own %exception classes, or use a different hierarchy, or to
5497403Sobrien   *  throw non-class data (e.g., fundamental types).
5597403Sobrien   */
5697403Sobrien  class exception 
5797403Sobrien  {
5897403Sobrien  public:
5997403Sobrien    exception() throw() { }
6097403Sobrien    virtual ~exception() throw();
61171827Skan
6297403Sobrien    /** Returns a C-style character string describing the general cause
6397403Sobrien     *  of the current error.  */
6497403Sobrien    virtual const char* what() const throw();
6597403Sobrien  };
6697403Sobrien
6797403Sobrien  /** If an %exception is thrown which is not listed in a function's
6897403Sobrien   *  %exception specification, one of these may be thrown.  */
6997403Sobrien  class bad_exception : public exception 
7097403Sobrien  {
7197403Sobrien  public:
7297403Sobrien    bad_exception() throw() { }
73171827Skan
7497403Sobrien    // This declaration is not useless:
7597403Sobrien    // http://gcc.gnu.org/onlinedocs/gcc-3.0.2/gcc_6.html#SEC118
7697403Sobrien    virtual ~bad_exception() throw();
77171827Skan
78169691Skan    // See comment in eh_exception.cc.
79169691Skan    virtual const char* what() const throw();
8097403Sobrien  };
8197403Sobrien
8297403Sobrien  /// If you write a replacement %terminate handler, it must be of this type.
8397403Sobrien  typedef void (*terminate_handler) ();
84171827Skan
8597403Sobrien  /// If you write a replacement %unexpected handler, it must be of this type.
8697403Sobrien  typedef void (*unexpected_handler) ();
8797403Sobrien
8897403Sobrien  /// Takes a new handler function as an argument, returns the old function.
8997403Sobrien  terminate_handler set_terminate(terminate_handler) throw();
90171827Skan
9197403Sobrien  /** The runtime will call this function if %exception handling must be
92132720Skan   *  abandoned for any reason.  It can also be called by the user.  */
9397403Sobrien  void terminate() __attribute__ ((__noreturn__));
9497403Sobrien
9597403Sobrien  /// Takes a new handler function as an argument, returns the old function.
9697403Sobrien  unexpected_handler set_unexpected(unexpected_handler) throw();
97171827Skan
9897403Sobrien  /** The runtime will call this function if an %exception is thrown which
9997403Sobrien   *  violates the function's %exception specification.  */
10097403Sobrien  void unexpected() __attribute__ ((__noreturn__));
10197403Sobrien
10297403Sobrien  /** [18.6.4]/1:  "Returns true after completing evaluation of a
10397403Sobrien   *  throw-expression until either completing initialization of the
10497403Sobrien   *  exception-declaration in the matching handler or entering @c unexpected()
10597403Sobrien   *  due to the throw; or after entering @c terminate() for any reason
10697403Sobrien   *  other than an explicit call to @c terminate().  [Note: This includes
10797403Sobrien   *  stack unwinding [15.2].  end note]"
10897403Sobrien   *
10997403Sobrien   *  2:  "When @c uncaught_exception() is true, throwing an %exception can
11097403Sobrien   *  result in a call of @c terminate() (15.5.1)."
11197403Sobrien   */
11297403Sobrien  bool uncaught_exception() throw();
11397403Sobrien} // namespace std
11497403Sobrien
115169691Skan_GLIBCXX_BEGIN_NAMESPACE(__gnu_cxx)
116169691Skan
11797403Sobrien  /** A replacement for the standard terminate_handler which prints more
11897403Sobrien      information about the terminating exception (if any) on stderr.  Call
11997403Sobrien      @code
12097403Sobrien        std::set_terminate (__gnu_cxx::__verbose_terminate_handler)
12197403Sobrien      @endcode
12297403Sobrien      to use.  For more info, see
12397403Sobrien      http://gcc.gnu.org/onlinedocs/libstdc++/19_diagnostics/howto.html#4
124132720Skan
125132720Skan      In 3.4 and later, this is on by default.
12697403Sobrien  */
12797403Sobrien  void __verbose_terminate_handler ();
128169691Skan
129169691Skan_GLIBCXX_END_NAMESPACE
13097403Sobrien  
13197403Sobrien} // extern "C++"
13297403Sobrien
133169691Skan#pragma GCC visibility pop
134169691Skan
13597403Sobrien#endif
136