libstdc++
|
00001 // Standard exception classes -*- C++ -*- 00002 00003 // Copyright (C) 2001, 2002, 2005, 2007, 2009, 2010 00004 // Free Software Foundation, Inc. 00005 // 00006 // This file is part of the GNU ISO C++ Library. This library is free 00007 // software; you can redistribute it and/or modify it under the 00008 // terms of the GNU General Public License as published by the 00009 // Free Software Foundation; either version 3, or (at your option) 00010 // any later version. 00011 00012 // This library is distributed in the hope that it will be useful, 00013 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00015 // GNU General Public License for more details. 00016 00017 // Under Section 7 of GPL version 3, you are granted additional 00018 // permissions described in the GCC Runtime Library Exception, version 00019 // 3.1, as published by the Free Software Foundation. 00020 00021 // You should have received a copy of the GNU General Public License and 00022 // a copy of the GCC Runtime Library Exception along with this program; 00023 // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see 00024 // <http://www.gnu.org/licenses/>. 00025 00026 /** @file include/stdexcept 00027 * This is a Standard C++ Library header. 00028 */ 00029 00030 // 00031 // ISO C++ 19.1 Exception classes 00032 // 00033 00034 #ifndef _GLIBCXX_STDEXCEPT 00035 #define _GLIBCXX_STDEXCEPT 1 00036 00037 #pragma GCC system_header 00038 00039 #include <exception> 00040 #include <string> 00041 00042 namespace std _GLIBCXX_VISIBILITY(default) 00043 { 00044 _GLIBCXX_BEGIN_NAMESPACE_VERSION 00045 00046 /** 00047 * @addtogroup exceptions 00048 * @{ 00049 */ 00050 00051 /** Logic errors represent problems in the internal logic of a program; 00052 * in theory, these are preventable, and even detectable before the 00053 * program runs (e.g., violations of class invariants). 00054 * @brief One of two subclasses of exception. 00055 */ 00056 class logic_error : public exception 00057 { 00058 string _M_msg; 00059 00060 public: 00061 /** Takes a character string describing the error. */ 00062 explicit 00063 logic_error(const string& __arg); 00064 00065 virtual 00066 ~logic_error() throw(); 00067 00068 /** Returns a C-style character string describing the general cause of 00069 * the current error (the same string passed to the ctor). */ 00070 virtual const char* 00071 what() const throw(); 00072 }; 00073 00074 /** Thrown by the library, or by you, to report domain errors (domain in 00075 * the mathematical sense). */ 00076 class domain_error : public logic_error 00077 { 00078 public: 00079 explicit domain_error(const string& __arg); 00080 }; 00081 00082 /** Thrown to report invalid arguments to functions. */ 00083 class invalid_argument : public logic_error 00084 { 00085 public: 00086 explicit invalid_argument(const string& __arg); 00087 }; 00088 00089 /** Thrown when an object is constructed that would exceed its maximum 00090 * permitted size (e.g., a basic_string instance). */ 00091 class length_error : public logic_error 00092 { 00093 public: 00094 explicit length_error(const string& __arg); 00095 }; 00096 00097 /** This represents an argument whose value is not within the expected 00098 * range (e.g., boundary checks in basic_string). */ 00099 class out_of_range : public logic_error 00100 { 00101 public: 00102 explicit out_of_range(const string& __arg); 00103 }; 00104 00105 /** Runtime errors represent problems outside the scope of a program; 00106 * they cannot be easily predicted and can generally only be caught as 00107 * the program executes. 00108 * @brief One of two subclasses of exception. 00109 */ 00110 class runtime_error : public exception 00111 { 00112 string _M_msg; 00113 00114 public: 00115 /** Takes a character string describing the error. */ 00116 explicit 00117 runtime_error(const string& __arg); 00118 00119 virtual 00120 ~runtime_error() throw(); 00121 00122 /** Returns a C-style character string describing the general cause of 00123 * the current error (the same string passed to the ctor). */ 00124 virtual const char* 00125 what() const throw(); 00126 }; 00127 00128 /** Thrown to indicate range errors in internal computations. */ 00129 class range_error : public runtime_error 00130 { 00131 public: 00132 explicit range_error(const string& __arg); 00133 }; 00134 00135 /** Thrown to indicate arithmetic overflow. */ 00136 class overflow_error : public runtime_error 00137 { 00138 public: 00139 explicit overflow_error(const string& __arg); 00140 }; 00141 00142 /** Thrown to indicate arithmetic underflow. */ 00143 class underflow_error : public runtime_error 00144 { 00145 public: 00146 explicit underflow_error(const string& __arg); 00147 }; 00148 00149 // @} group exceptions 00150 00151 _GLIBCXX_END_NAMESPACE_VERSION 00152 } // namespace 00153 00154 #endif /* _GLIBCXX_STDEXCEPT */