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