std_stdexcept.h revision 132720
1226633Sdim// Standard exception classes  -*- C++ -*-
2193323Sed
3193323Sed// Copyright (C) 2001, 2002 Free Software Foundation, Inc.
4193323Sed//
5193323Sed// This file is part of the GNU ISO C++ Library.  This library is free
6193323Sed// software; you can redistribute it and/or modify it under the
7193323Sed// terms of the GNU General Public License as published by the
8193323Sed// Free Software Foundation; either version 2, or (at your option)
9193323Sed// any later version.
10193323Sed
11193323Sed// This library is distributed in the hope that it will be useful,
12193323Sed// but WITHOUT ANY WARRANTY; without even the implied warranty of
13193323Sed// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14193323Sed// GNU General Public License for more details.
15193323Sed
16193323Sed// You should have received a copy of the GNU General Public License along
17193323Sed// with this library; see the file COPYING.  If not, write to the Free
18193323Sed// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
19193323Sed// USA.
20193323Sed
21193323Sed// As a special exception, you may use this file as part of a free software
22193323Sed// library without restriction.  Specifically, if other files instantiate
23193323Sed// templates or use macros or inline functions from this file, or you compile
24249423Sdim// this file and link it with other files to produce an executable, this
25193323Sed// file does not by itself cause the resulting executable to be covered by
26193323Sed// the GNU General Public License.  This exception does not however
27193323Sed// invalidate any other reasons why the executable file might be covered by
28193323Sed// the GNU General Public License.
29193323Sed
30193323Sed//
31193323Sed// ISO C++ 19.1  Exception classes
32193323Sed//
33193323Sed
34193323Sed/** @file stdexcept
35193323Sed *  This is a Standard C++ Library header.  You should @c #include this header
36193323Sed *  in your programs, rather than any of the "st[dl]_*.h" implementation files.
37198090Srdivacky */
38198090Srdivacky
39193323Sed#ifndef _GLIBCXX_STDEXCEPT
40193323Sed#define _GLIBCXX_STDEXCEPT 1
41193323Sed
42198090Srdivacky#pragma GCC system_header
43198090Srdivacky
44193323Sed#include <exception>
45193323Sed#include <string>
46193323Sed
47193323Sednamespace std
48193323Sed{
49193323Sed  /** Logic errors represent problems in the internal logic of a program;
50193323Sed   *  in theory, these are preventable, and even detectable before the
51198090Srdivacky   *  program runs (e.g., violations of class invariants).
52193323Sed   *  @brief One of two subclasses of exception.
53193323Sed   */
54193323Sed  class logic_error : public exception
55193323Sed  {
56193323Sed    string _M_msg;
57193323Sed
58193323Sed  public:
59193323Sed    /** Takes a character string describing the error.  */
60193323Sed    explicit
61193323Sed    logic_error(const string&  __arg);
62193323Sed
63218893Sdim    virtual
64193323Sed    ~logic_error() throw();
65193323Sed
66193323Sed    /** Returns a C-style character string describing the general cause of
67193323Sed     *  the current error (the same string passed to the ctor).  */
68193323Sed    virtual const char*
69207618Srdivacky    what() const throw();
70193323Sed  };
71193323Sed
72193323Sed  /** Thrown by the library, or by you, to report domain errors (domain in
73193323Sed   *  the mathmatical sense).  */
74193323Sed  class domain_error : public logic_error
75201360Srdivacky  {
76193323Sed  public:
77193323Sed    explicit domain_error(const string&  __arg);
78193323Sed  };
79193323Sed
80193323Sed  /** Thrown to report invalid arguments to functions.  */
81193323Sed  class invalid_argument : public logic_error
82193323Sed  {
83193323Sed  public:
84193323Sed    explicit invalid_argument(const string&  __arg);
85193323Sed  };
86207618Srdivacky
87193323Sed  /** Thrown when an object is constructed that would exceed its maximum
88207618Srdivacky   *  permitted size (e.g., a basic_string instance).  */
89193323Sed  class length_error : public logic_error
90226633Sdim  {
91207618Srdivacky  public:
92207618Srdivacky    explicit length_error(const string&  __arg);
93207618Srdivacky  };
94193323Sed
95193323Sed  /** This represents an argument whose value is not within the expected
96193323Sed   *  range (e.g., boundary checks in basic_string).  */
97193323Sed  class out_of_range : public logic_error
98193323Sed  {
99193323Sed  public:
100193323Sed    explicit out_of_range(const string&  __arg);
101193323Sed  };
102193323Sed
103193323Sed  /** Runtime errors represent problems outside the scope of a program;
104207618Srdivacky   *  they cannot be easily predicted and can generally only be caught as
105193323Sed   *  the program executes.
106193323Sed   *  @brief One of two subclasses of exception.
107193323Sed   */
108193323Sed  class runtime_error : public exception
109193323Sed  {
110193323Sed    string _M_msg;
111201360Srdivacky
112193323Sed  public:
113193323Sed    /** Takes a character string describing the error.  */
114193323Sed    explicit
115207618Srdivacky    runtime_error(const string&  __arg);
116207618Srdivacky
117226633Sdim    virtual
118207618Srdivacky    ~runtime_error() throw();
119207618Srdivacky
120207618Srdivacky    /** Returns a C-style character string describing the general cause of
121207618Srdivacky     *  the current error (the same string passed to the ctor).  */
122207618Srdivacky    virtual const char*
123207618Srdivacky    what() const throw();
124207618Srdivacky  };
125207618Srdivacky
126207618Srdivacky  /** Thrown to indicate range errors in internal computations.  */
127207618Srdivacky  class range_error : public runtime_error
128193323Sed  {
129193323Sed  public:
130193323Sed    explicit range_error(const string&  __arg);
131193323Sed  };
132193323Sed
133193323Sed  /** Thrown to indicate arithmetic overflow.  */
134193323Sed  class overflow_error : public runtime_error
135193323Sed  {
136193323Sed  public:
137193323Sed    explicit overflow_error(const string&  __arg);
138193323Sed  };
139193323Sed
140193323Sed  /** Thrown to indicate arithmetic underflow.  */
141207618Srdivacky  class underflow_error : public runtime_error
142226633Sdim  {
143193323Sed  public:
144207618Srdivacky    explicit underflow_error(const string&  __arg);
145207618Srdivacky  };
146193323Sed} // namespace std
147193323Sed
148193323Sed#endif /* _GLIBCXX_STDEXCEPT */
149193323Sed