libstdc++
|
00001 // class template regex -*- C++ -*- 00002 00003 // Copyright (C) 2010-2019 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 /** 00026 * @file bits/regex_error.h 00027 * @brief Error and exception objects for the std regex library. 00028 * 00029 * This is an internal header file, included by other library headers. 00030 * Do not attempt to use it directly. @headername{regex} 00031 */ 00032 00033 namespace std _GLIBCXX_VISIBILITY(default) 00034 { 00035 _GLIBCXX_BEGIN_NAMESPACE_VERSION 00036 00037 /** 00038 * @addtogroup regex 00039 * @{ 00040 */ 00041 00042 namespace regex_constants 00043 { 00044 /** 00045 * @name 5.3 Error Types 00046 */ 00047 //@{ 00048 00049 enum error_type 00050 { 00051 _S_error_collate, 00052 _S_error_ctype, 00053 _S_error_escape, 00054 _S_error_backref, 00055 _S_error_brack, 00056 _S_error_paren, 00057 _S_error_brace, 00058 _S_error_badbrace, 00059 _S_error_range, 00060 _S_error_space, 00061 _S_error_badrepeat, 00062 _S_error_complexity, 00063 _S_error_stack, 00064 }; 00065 00066 /** The expression contained an invalid collating element name. */ 00067 constexpr error_type error_collate(_S_error_collate); 00068 00069 /** The expression contained an invalid character class name. */ 00070 constexpr error_type error_ctype(_S_error_ctype); 00071 00072 /** 00073 * The expression contained an invalid escaped character, or a trailing 00074 * escape. 00075 */ 00076 constexpr error_type error_escape(_S_error_escape); 00077 00078 /** The expression contained an invalid back reference. */ 00079 constexpr error_type error_backref(_S_error_backref); 00080 00081 /** The expression contained mismatched [ and ]. */ 00082 constexpr error_type error_brack(_S_error_brack); 00083 00084 /** The expression contained mismatched ( and ). */ 00085 constexpr error_type error_paren(_S_error_paren); 00086 00087 /** The expression contained mismatched { and } */ 00088 constexpr error_type error_brace(_S_error_brace); 00089 00090 /** The expression contained an invalid range in a {} expression. */ 00091 constexpr error_type error_badbrace(_S_error_badbrace); 00092 00093 /** 00094 * The expression contained an invalid character range, 00095 * such as [b-a] in most encodings. 00096 */ 00097 constexpr error_type error_range(_S_error_range); 00098 00099 /** 00100 * There was insufficient memory to convert the expression into a 00101 * finite state machine. 00102 */ 00103 constexpr error_type error_space(_S_error_space); 00104 00105 /** 00106 * One of <em>*?+{</em> was not preceded by a valid regular expression. 00107 */ 00108 constexpr error_type error_badrepeat(_S_error_badrepeat); 00109 00110 /** 00111 * The complexity of an attempted match against a regular expression 00112 * exceeded a pre-set level. 00113 */ 00114 constexpr error_type error_complexity(_S_error_complexity); 00115 00116 /** 00117 * There was insufficient memory to determine whether the 00118 * regular expression could match the specified character sequence. 00119 */ 00120 constexpr error_type error_stack(_S_error_stack); 00121 00122 //@} 00123 } // namespace regex_constants 00124 00125 // [7.8] Class regex_error 00126 /** 00127 * @brief A regular expression exception class. 00128 * @ingroup exceptions 00129 * 00130 * The regular expression library throws objects of this class on error. 00131 */ 00132 class regex_error : public std::runtime_error 00133 { 00134 regex_constants::error_type _M_code; 00135 00136 public: 00137 /** 00138 * @brief Constructs a regex_error object. 00139 * 00140 * @param __ecode the regex error code. 00141 */ 00142 explicit 00143 regex_error(regex_constants::error_type __ecode); 00144 00145 virtual ~regex_error() throw(); 00146 00147 /** 00148 * @brief Gets the regex error code. 00149 * 00150 * @returns the regex error code. 00151 */ 00152 regex_constants::error_type 00153 code() const 00154 { return _M_code; } 00155 00156 private: 00157 regex_error(regex_constants::error_type __ecode, const char* __what) 00158 : std::runtime_error(__what), _M_code(__ecode) 00159 { } 00160 00161 friend void __throw_regex_error(regex_constants::error_type, const char*); 00162 }; 00163 00164 //@} // group regex 00165 00166 void 00167 __throw_regex_error(regex_constants::error_type __ecode); 00168 00169 inline void 00170 __throw_regex_error(regex_constants::error_type __ecode, const char* __what) 00171 { _GLIBCXX_THROW_OR_ABORT(regex_error(__ecode, __what)); } 00172 00173 _GLIBCXX_END_NAMESPACE_VERSION 00174 } // namespace std