1 // Standard exception classes -*- C++ -*- 2 3 // Copyright (C) 2001, 2002 Free Software Foundation, Inc. 4 // 5 // This file is part of the GNU ISO C++ Library. This library is free 6 // software; you can redistribute it and/or modify it under the 7 // terms of the GNU General Public License as published by the 8 // Free Software Foundation; either version 2, or (at your option) 9 // any later version. 10 11 // This library is distributed in the hope that it will be useful, 12 // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 // GNU General Public License for more details. 15 16 // You should have received a copy of the GNU General Public License along 17 // with this library; see the file COPYING. If not, write to the Free 18 // Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, 19 // USA. 20 21 // As a special exception, you may use this file as part of a free software 22 // library without restriction. Specifically, if other files instantiate 23 // templates or use macros or inline functions from this file, or you compile 24 // this file and link it with other files to produce an executable, this 25 // file does not by itself cause the resulting executable to be covered by 26 // the GNU General Public License. This exception does not however 27 // invalidate any other reasons why the executable file might be covered by 28 // the GNU General Public License. 29 30 // 31 // ISO C++ 19.1 Exception classes 32 // 33 34 /** @file stdexcept 35 * This is a Standard C++ Library header. You should @c #include this header 36 * in your programs, rather than any of the "st[dl]_*.h" implementation files. 37 */ 38 39 #ifndef _GLIBCXX_STDEXCEPT 40 #define _GLIBCXX_STDEXCEPT 1 41 42 #pragma GCC system_header 43 44 #include <exception> 45 #include <string> 46 47 namespace std 48 { 49 /** Logic errors represent problems in the internal logic of a program; 50 * in theory, these are preventable, and even detectable before the 51 * program runs (e.g., violations of class invariants). 52 * @brief One of two subclasses of exception. 53 */ 54 class logic_error : public exception 55 { 56 string _M_msg; 57 58 public: 59 /** Takes a character string describing the error. */ 60 explicit 61 logic_error(const string& __arg); 62 63 virtual 64 ~logic_error() throw(); 65 66 /** Returns a C-style character string describing the general cause of 67 * the current error (the same string passed to the ctor). */ 68 virtual const char* 69 what() const throw(); 70 }; 71 72 /** Thrown by the library, or by you, to report domain errors (domain in 73 * the mathmatical sense). */ 74 class domain_error : public logic_error 75 { 76 public: 77 explicit domain_error(const string& __arg); 78 }; 79 80 /** Thrown to report invalid arguments to functions. */ 81 class invalid_argument : public logic_error 82 { 83 public: 84 explicit invalid_argument(const string& __arg); 85 }; 86 87 /** Thrown when an object is constructed that would exceed its maximum 88 * permitted size (e.g., a basic_string instance). */ 89 class length_error : public logic_error 90 { 91 public: 92 explicit length_error(const string& __arg); 93 }; 94 95 /** This represents an argument whose value is not within the expected 96 * range (e.g., boundary checks in basic_string). */ 97 class out_of_range : public logic_error 98 { 99 public: 100 explicit out_of_range(const string& __arg); 101 }; 102 103 /** Runtime errors represent problems outside the scope of a program; 104 * they cannot be easily predicted and can generally only be caught as 105 * the program executes. 106 * @brief One of two subclasses of exception. 107 */ 108 class runtime_error : public exception 109 { 110 string _M_msg; 111 112 public: 113 /** Takes a character string describing the error. */ 114 explicit 115 runtime_error(const string& __arg); 116 117 virtual 118 ~runtime_error() throw(); 119 120 /** Returns a C-style character string describing the general cause of 121 * the current error (the same string passed to the ctor). */ 122 virtual const char* 123 what() const throw(); 124 }; 125 126 /** Thrown to indicate range errors in internal computations. */ 127 class range_error : public runtime_error 128 { 129 public: 130 explicit range_error(const string& __arg); 131 }; 132 133 /** Thrown to indicate arithmetic overflow. */ 134 class overflow_error : public runtime_error 135 { 136 public: 137 explicit overflow_error(const string& __arg); 138 }; 139 140 /** Thrown to indicate arithmetic underflow. */ 141 class underflow_error : public runtime_error 142 { 143 public: 144 explicit underflow_error(const string& __arg); 145 }; 146 } // namespace std 147 148 #endif /* _GLIBCXX_STDEXCEPT */ 149