std_stdexcept.h revision 97403
1264790Sbapt// Standard exception classes  -*- C++ -*-
2264790Sbapt
3264790Sbapt// Copyright (C) 2001, 2002 Free Software Foundation, Inc.
4264790Sbapt//
5264790Sbapt// This file is part of the GNU ISO C++ Library.  This library is free
6264790Sbapt// software; you can redistribute it and/or modify it under the
7264790Sbapt// terms of the GNU General Public License as published by the
8264790Sbapt// Free Software Foundation; either version 2, or (at your option)
9264790Sbapt// any later version.
10264790Sbapt
11264790Sbapt// This library is distributed in the hope that it will be useful,
12264790Sbapt// but WITHOUT ANY WARRANTY; without even the implied warranty of
13264790Sbapt// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14264790Sbapt// GNU General Public License for more details.
15264790Sbapt
16264790Sbapt// You should have received a copy of the GNU General Public License along
17264790Sbapt// with this library; see the file COPYING.  If not, write to the Free
18264790Sbapt// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
19264790Sbapt// USA.
20264790Sbapt
21264790Sbapt// As a special exception, you may use this file as part of a free software
22264790Sbapt// library without restriction.  Specifically, if other files instantiate
23264790Sbapt// templates or use macros or inline functions from this file, or you compile
24264790Sbapt// this file and link it with other files to produce an executable, this
25264790Sbapt// file does not by itself cause the resulting executable to be covered by
26264790Sbapt// the GNU General Public License.  This exception does not however
27264790Sbapt// invalidate any other reasons why the executable file might be covered by
28264790Sbapt// the GNU General Public License.
29264790Sbapt
30264790Sbapt//
31264790Sbapt// ISO C++ 19.1  Exception classes
32264790Sbapt//
33264790Sbapt
34264790Sbapt/** @file stdexcept
35264790Sbapt *  This is a Standard C++ Library header.  You should @c #include this header
36264790Sbapt *  in your programs, rather than any of the "st[dl]_*.h" implementation files.
37264790Sbapt */
38264790Sbapt
39264790Sbapt#ifndef _CPP_STDEXCEPT
40264790Sbapt#define _CPP_STDEXCEPT 	  1
41264790Sbapt
42264790Sbapt#pragma GCC system_header
43264790Sbapt
44264790Sbapt#include <exception>
45264790Sbapt#include <string>
46264790Sbapt
47264790Sbaptnamespace std
48264790Sbapt{
49264790Sbapt  /** Logic errors represent problems in the internal logic of a program;
50264790Sbapt   *  in theory, these are preventable, and even detectable before the
51264790Sbapt   *  program runs (e.g., violations of class invariants).
52264790Sbapt   *  @brief One of two subclasses of exception.
53264790Sbapt   */
54264790Sbapt  class logic_error : public exception
55264790Sbapt  {
56264790Sbapt    string _M_msg;
57264790Sbapt
58264790Sbapt  public:
59264790Sbapt    /** Takes a character string describing the error.  */
60264790Sbapt    explicit
61264790Sbapt    logic_error(const string&  __arg);
62264790Sbapt
63264790Sbapt    virtual
64264790Sbapt    ~logic_error() throw();
65264790Sbapt
66264790Sbapt    /** Returns a C-style character string describing the general cause of
67264790Sbapt     *  the current error (the same string passed to the ctor).  */
68264790Sbapt    virtual const char*
69264790Sbapt    what() const throw();
70264790Sbapt  };
71264790Sbapt
72264790Sbapt  /** Thrown by the library, or by you, to report domain errors (domain in
73264790Sbapt   *  the mathmatical sense).  */
74264790Sbapt  class domain_error : public logic_error
75264790Sbapt  {
76264790Sbapt  public:
77264790Sbapt    explicit domain_error(const string&  __arg);
78264790Sbapt  };
79264790Sbapt
80264790Sbapt  /** Thrown to report invalid arguments to functions.  */
81264790Sbapt  class invalid_argument : public logic_error
82264790Sbapt  {
83264790Sbapt  public:
84264790Sbapt    explicit invalid_argument(const string&  __arg);
85264790Sbapt  };
86264790Sbapt
87264790Sbapt  /** Thrown when an object is constructed that would exceed its maximum
88264790Sbapt   *  permitted size (e.g., a basic_string instance).  */
89264790Sbapt  class length_error : public logic_error
90264790Sbapt  {
91264790Sbapt  public:
92264790Sbapt    explicit length_error(const string&  __arg);
93264790Sbapt  };
94264790Sbapt
95264790Sbapt  /** This represents an argument whose value is not within the expected
96264790Sbapt   *  range (e.g., boundary checks in basic_string).  */
97264790Sbapt  class out_of_range : public logic_error
98264790Sbapt  {
99264790Sbapt  public:
100264790Sbapt    explicit out_of_range(const string&  __arg);
101264790Sbapt  };
102264790Sbapt
103264790Sbapt  /** Runtime errors represent problems outside the scope of a program;
104264790Sbapt   *  they cannot be easily predicted and can generally only be caught as
105264790Sbapt   *  the program executes.
106264790Sbapt   *  @brief One of two subclasses of exception.
107264790Sbapt   */
108264790Sbapt  class runtime_error : public exception
109264790Sbapt  {
110264790Sbapt    string _M_msg;
111264790Sbapt
112264790Sbapt  public:
113264790Sbapt    /** Takes a character string describing the error.  */
114264790Sbapt    explicit
115264790Sbapt    runtime_error(const string&  __arg);
116264790Sbapt
117264790Sbapt    virtual
118264790Sbapt    ~runtime_error() throw();
119264790Sbapt
120264790Sbapt    /** Returns a C-style character string describing the general cause of
121264790Sbapt     *  the current error (the same string passed to the ctor).  */
122264790Sbapt    virtual const char*
123264790Sbapt    what() const throw();
124264790Sbapt  };
125264790Sbapt
126264790Sbapt  /** Thrown to indicate range errors in internal computations.  */
127264790Sbapt  class range_error : public runtime_error
128264790Sbapt  {
129264790Sbapt  public:
130264790Sbapt    explicit range_error(const string&  __arg);
131264790Sbapt  };
132264790Sbapt
133264790Sbapt  /** Thrown to indicate arithmetic overflow.  */
134264790Sbapt  class overflow_error : public runtime_error
135264790Sbapt  {
136264790Sbapt  public:
137264790Sbapt    explicit overflow_error(const string&  __arg);
138264790Sbapt  };
139264790Sbapt
140264790Sbapt  /** Thrown to indicate arithmetic underflow.  */
141264790Sbapt  class underflow_error : public runtime_error
142264790Sbapt  {
143264790Sbapt  public:
144264790Sbapt    explicit underflow_error(const string&  __arg);
145264790Sbapt  };
146264790Sbapt} // namespace std
147264790Sbapt
148264790Sbapt#endif // _CPP_STDEXCEPT
149264790Sbapt