197403Sobrien// Standard exception classes  -*- C++ -*-
297403Sobrien
3169691Skan// Copyright (C) 2001, 2002, 2005 Free Software Foundation, Inc.
497403Sobrien//
597403Sobrien// This file is part of the GNU ISO C++ Library.  This library is free
697403Sobrien// software; you can redistribute it and/or modify it under the
797403Sobrien// terms of the GNU General Public License as published by the
897403Sobrien// Free Software Foundation; either version 2, or (at your option)
997403Sobrien// any later version.
1097403Sobrien
1197403Sobrien// This library is distributed in the hope that it will be useful,
1297403Sobrien// but WITHOUT ANY WARRANTY; without even the implied warranty of
1397403Sobrien// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
1497403Sobrien// GNU General Public License for more details.
1597403Sobrien
1697403Sobrien// You should have received a copy of the GNU General Public License along
1797403Sobrien// with this library; see the file COPYING.  If not, write to the Free
18169691Skan// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
1997403Sobrien// USA.
2097403Sobrien
2197403Sobrien// As a special exception, you may use this file as part of a free software
2297403Sobrien// library without restriction.  Specifically, if other files instantiate
2397403Sobrien// templates or use macros or inline functions from this file, or you compile
2497403Sobrien// this file and link it with other files to produce an executable, this
2597403Sobrien// file does not by itself cause the resulting executable to be covered by
2697403Sobrien// the GNU General Public License.  This exception does not however
2797403Sobrien// invalidate any other reasons why the executable file might be covered by
2897403Sobrien// the GNU General Public License.
2997403Sobrien
30169691Skan/** @file stdexcept
31169691Skan *  This is a Standard C++ Library header.
32169691Skan */
33169691Skan
3497403Sobrien//
3597403Sobrien// ISO C++ 19.1  Exception classes
3697403Sobrien//
3797403Sobrien
38132720Skan#ifndef _GLIBCXX_STDEXCEPT
39132720Skan#define _GLIBCXX_STDEXCEPT 1
4097403Sobrien
4197403Sobrien#pragma GCC system_header
4297403Sobrien
4397403Sobrien#include <exception>
4497403Sobrien#include <string>
4597403Sobrien
46169691Skan_GLIBCXX_BEGIN_NAMESPACE(std)
47169691Skan
4897403Sobrien  /** Logic errors represent problems in the internal logic of a program;
4997403Sobrien   *  in theory, these are preventable, and even detectable before the
5097403Sobrien   *  program runs (e.g., violations of class invariants).
5197403Sobrien   *  @brief One of two subclasses of exception.
5297403Sobrien   */
5397403Sobrien  class logic_error : public exception
5497403Sobrien  {
5597403Sobrien    string _M_msg;
5697403Sobrien
5797403Sobrien  public:
5897403Sobrien    /** Takes a character string describing the error.  */
5997403Sobrien    explicit
6097403Sobrien    logic_error(const string&  __arg);
6197403Sobrien
6297403Sobrien    virtual
6397403Sobrien    ~logic_error() throw();
6497403Sobrien
6597403Sobrien    /** Returns a C-style character string describing the general cause of
6697403Sobrien     *  the current error (the same string passed to the ctor).  */
6797403Sobrien    virtual const char*
6897403Sobrien    what() const throw();
6997403Sobrien  };
7097403Sobrien
7197403Sobrien  /** Thrown by the library, or by you, to report domain errors (domain in
7297403Sobrien   *  the mathmatical sense).  */
7397403Sobrien  class domain_error : public logic_error
7497403Sobrien  {
7597403Sobrien  public:
7697403Sobrien    explicit domain_error(const string&  __arg);
7797403Sobrien  };
7897403Sobrien
7997403Sobrien  /** Thrown to report invalid arguments to functions.  */
8097403Sobrien  class invalid_argument : public logic_error
8197403Sobrien  {
8297403Sobrien  public:
8397403Sobrien    explicit invalid_argument(const string&  __arg);
8497403Sobrien  };
8597403Sobrien
8697403Sobrien  /** Thrown when an object is constructed that would exceed its maximum
8797403Sobrien   *  permitted size (e.g., a basic_string instance).  */
8897403Sobrien  class length_error : public logic_error
8997403Sobrien  {
9097403Sobrien  public:
9197403Sobrien    explicit length_error(const string&  __arg);
9297403Sobrien  };
9397403Sobrien
9497403Sobrien  /** This represents an argument whose value is not within the expected
9597403Sobrien   *  range (e.g., boundary checks in basic_string).  */
9697403Sobrien  class out_of_range : public logic_error
9797403Sobrien  {
9897403Sobrien  public:
9997403Sobrien    explicit out_of_range(const string&  __arg);
10097403Sobrien  };
10197403Sobrien
10297403Sobrien  /** Runtime errors represent problems outside the scope of a program;
10397403Sobrien   *  they cannot be easily predicted and can generally only be caught as
10497403Sobrien   *  the program executes.
10597403Sobrien   *  @brief One of two subclasses of exception.
10697403Sobrien   */
10797403Sobrien  class runtime_error : public exception
10897403Sobrien  {
10997403Sobrien    string _M_msg;
11097403Sobrien
11197403Sobrien  public:
11297403Sobrien    /** Takes a character string describing the error.  */
11397403Sobrien    explicit
11497403Sobrien    runtime_error(const string&  __arg);
11597403Sobrien
11697403Sobrien    virtual
11797403Sobrien    ~runtime_error() throw();
11897403Sobrien
11997403Sobrien    /** Returns a C-style character string describing the general cause of
12097403Sobrien     *  the current error (the same string passed to the ctor).  */
12197403Sobrien    virtual const char*
12297403Sobrien    what() const throw();
12397403Sobrien  };
12497403Sobrien
12597403Sobrien  /** Thrown to indicate range errors in internal computations.  */
12697403Sobrien  class range_error : public runtime_error
12797403Sobrien  {
12897403Sobrien  public:
12997403Sobrien    explicit range_error(const string&  __arg);
13097403Sobrien  };
13197403Sobrien
13297403Sobrien  /** Thrown to indicate arithmetic overflow.  */
13397403Sobrien  class overflow_error : public runtime_error
13497403Sobrien  {
13597403Sobrien  public:
13697403Sobrien    explicit overflow_error(const string&  __arg);
13797403Sobrien  };
13897403Sobrien
13997403Sobrien  /** Thrown to indicate arithmetic underflow.  */
14097403Sobrien  class underflow_error : public runtime_error
14197403Sobrien  {
14297403Sobrien  public:
14397403Sobrien    explicit underflow_error(const string&  __arg);
14497403Sobrien  };
14597403Sobrien
146169691Skan_GLIBCXX_END_NAMESPACE
147169691Skan
148132720Skan#endif /* _GLIBCXX_STDEXCEPT */
149