1*0a307195Smrg // Errors for std::regex -*- C++ -*-
248fb7bfaSmrg
3b1e83836Smrg // Copyright (C) 2010-2022 Free Software Foundation, Inc.
448fb7bfaSmrg //
548fb7bfaSmrg // This file is part of the GNU ISO C++ Library. This library is free
648fb7bfaSmrg // software; you can redistribute it and/or modify it under the
748fb7bfaSmrg // terms of the GNU General Public License as published by the
848fb7bfaSmrg // Free Software Foundation; either version 3, or (at your option)
948fb7bfaSmrg // any later version.
1048fb7bfaSmrg
1148fb7bfaSmrg // This library is distributed in the hope that it will be useful,
1248fb7bfaSmrg // but WITHOUT ANY WARRANTY; without even the implied warranty of
1348fb7bfaSmrg // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1448fb7bfaSmrg // GNU General Public License for more details.
1548fb7bfaSmrg
1648fb7bfaSmrg // Under Section 7 of GPL version 3, you are granted additional
1748fb7bfaSmrg // permissions described in the GCC Runtime Library Exception, version
1848fb7bfaSmrg // 3.1, as published by the Free Software Foundation.
1948fb7bfaSmrg
2048fb7bfaSmrg // You should have received a copy of the GNU General Public License and
2148fb7bfaSmrg // a copy of the GCC Runtime Library Exception along with this program;
2248fb7bfaSmrg // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
2348fb7bfaSmrg // <http://www.gnu.org/licenses/>.
2448fb7bfaSmrg
2548fb7bfaSmrg /**
2648fb7bfaSmrg * @file bits/regex_error.h
2748fb7bfaSmrg * @brief Error and exception objects for the std regex library.
2848fb7bfaSmrg *
2948fb7bfaSmrg * This is an internal header file, included by other library headers.
3048fb7bfaSmrg * Do not attempt to use it directly. @headername{regex}
3148fb7bfaSmrg */
3248fb7bfaSmrg
_GLIBCXX_VISIBILITY(default)3348fb7bfaSmrg namespace std _GLIBCXX_VISIBILITY(default)
3448fb7bfaSmrg {
35a3e9eb18Smrg _GLIBCXX_BEGIN_NAMESPACE_VERSION
36a3e9eb18Smrg
3748fb7bfaSmrg /**
3848fb7bfaSmrg * @addtogroup regex
3948fb7bfaSmrg * @{
4048fb7bfaSmrg */
4148fb7bfaSmrg
4248fb7bfaSmrg namespace regex_constants
4348fb7bfaSmrg {
4448fb7bfaSmrg /**
4548fb7bfaSmrg * @name 5.3 Error Types
4648fb7bfaSmrg */
47a448f87cSmrg ///@{
4848fb7bfaSmrg
4948fb7bfaSmrg enum error_type
5048fb7bfaSmrg {
51b1e83836Smrg _S_error_collate, // XXX should have been a non-zero value
5248fb7bfaSmrg _S_error_ctype,
5348fb7bfaSmrg _S_error_escape,
5448fb7bfaSmrg _S_error_backref,
5548fb7bfaSmrg _S_error_brack,
5648fb7bfaSmrg _S_error_paren,
5748fb7bfaSmrg _S_error_brace,
5848fb7bfaSmrg _S_error_badbrace,
5948fb7bfaSmrg _S_error_range,
6048fb7bfaSmrg _S_error_space,
6148fb7bfaSmrg _S_error_badrepeat,
6248fb7bfaSmrg _S_error_complexity,
6348fb7bfaSmrg _S_error_stack,
647d4dc15bSmrg _S_null,
657d4dc15bSmrg _S_grammar
6648fb7bfaSmrg };
6748fb7bfaSmrg
6848fb7bfaSmrg /** The expression contained an invalid collating element name. */
69b1e83836Smrg _GLIBCXX17_INLINE constexpr error_type error_collate(_S_error_collate);
7048fb7bfaSmrg
7148fb7bfaSmrg /** The expression contained an invalid character class name. */
72b1e83836Smrg _GLIBCXX17_INLINE constexpr error_type error_ctype(_S_error_ctype);
7348fb7bfaSmrg
7448fb7bfaSmrg /**
7548fb7bfaSmrg * The expression contained an invalid escaped character, or a trailing
7648fb7bfaSmrg * escape.
7748fb7bfaSmrg */
78b1e83836Smrg _GLIBCXX17_INLINE constexpr error_type error_escape(_S_error_escape);
7948fb7bfaSmrg
8048fb7bfaSmrg /** The expression contained an invalid back reference. */
81b1e83836Smrg _GLIBCXX17_INLINE constexpr error_type error_backref(_S_error_backref);
8248fb7bfaSmrg
8348fb7bfaSmrg /** The expression contained mismatched [ and ]. */
84b1e83836Smrg _GLIBCXX17_INLINE constexpr error_type error_brack(_S_error_brack);
8548fb7bfaSmrg
8648fb7bfaSmrg /** The expression contained mismatched ( and ). */
87b1e83836Smrg _GLIBCXX17_INLINE constexpr error_type error_paren(_S_error_paren);
8848fb7bfaSmrg
8948fb7bfaSmrg /** The expression contained mismatched { and } */
90b1e83836Smrg _GLIBCXX17_INLINE constexpr error_type error_brace(_S_error_brace);
9148fb7bfaSmrg
9248fb7bfaSmrg /** The expression contained an invalid range in a {} expression. */
93b1e83836Smrg _GLIBCXX17_INLINE constexpr error_type error_badbrace(_S_error_badbrace);
9448fb7bfaSmrg
9548fb7bfaSmrg /**
9648fb7bfaSmrg * The expression contained an invalid character range,
9748fb7bfaSmrg * such as [b-a] in most encodings.
9848fb7bfaSmrg */
99b1e83836Smrg _GLIBCXX17_INLINE constexpr error_type error_range(_S_error_range);
10048fb7bfaSmrg
10148fb7bfaSmrg /**
10248fb7bfaSmrg * There was insufficient memory to convert the expression into a
10348fb7bfaSmrg * finite state machine.
10448fb7bfaSmrg */
105b1e83836Smrg _GLIBCXX17_INLINE constexpr error_type error_space(_S_error_space);
10648fb7bfaSmrg
10748fb7bfaSmrg /**
10848fb7bfaSmrg * One of <em>*?+{</em> was not preceded by a valid regular expression.
10948fb7bfaSmrg */
110b1e83836Smrg _GLIBCXX17_INLINE constexpr error_type error_badrepeat(_S_error_badrepeat);
11148fb7bfaSmrg
11248fb7bfaSmrg /**
11348fb7bfaSmrg * The complexity of an attempted match against a regular expression
11448fb7bfaSmrg * exceeded a pre-set level.
11548fb7bfaSmrg */
116b1e83836Smrg _GLIBCXX17_INLINE constexpr error_type error_complexity(_S_error_complexity);
11748fb7bfaSmrg
11848fb7bfaSmrg /**
11948fb7bfaSmrg * There was insufficient memory to determine whether the
12048fb7bfaSmrg * regular expression could match the specified character sequence.
12148fb7bfaSmrg */
122b1e83836Smrg _GLIBCXX17_INLINE constexpr error_type error_stack(_S_error_stack);
12348fb7bfaSmrg
124a448f87cSmrg ///@}
12548fb7bfaSmrg } // namespace regex_constants
12648fb7bfaSmrg
12748fb7bfaSmrg // [7.8] Class regex_error
12848fb7bfaSmrg /**
12948fb7bfaSmrg * @brief A regular expression exception class.
13048fb7bfaSmrg * @ingroup exceptions
13148fb7bfaSmrg *
13248fb7bfaSmrg * The regular expression library throws objects of this class on error.
133*0a307195Smrg *
134*0a307195Smrg * @headerfile regex
135*0a307195Smrg * @since C++11
13648fb7bfaSmrg */
13748fb7bfaSmrg class regex_error : public std::runtime_error
13848fb7bfaSmrg {
139b1e83836Smrg using error_type = regex_constants::error_type;
140b1e83836Smrg
141b1e83836Smrg error_type _M_code;
14248fb7bfaSmrg
14348fb7bfaSmrg public:
14448fb7bfaSmrg /**
14548fb7bfaSmrg * @brief Constructs a regex_error object.
14648fb7bfaSmrg *
14748fb7bfaSmrg * @param __ecode the regex error code.
14848fb7bfaSmrg */
14948fb7bfaSmrg explicit
150b1e83836Smrg regex_error(error_type __ecode);
15148fb7bfaSmrg
15248fb7bfaSmrg virtual ~regex_error() throw();
15348fb7bfaSmrg
15448fb7bfaSmrg /**
15548fb7bfaSmrg * @brief Gets the regex error code.
15648fb7bfaSmrg *
15748fb7bfaSmrg * @returns the regex error code.
15848fb7bfaSmrg */
15948fb7bfaSmrg regex_constants::error_type
1607d4dc15bSmrg code() const noexcept
16148fb7bfaSmrg { return _M_code; }
162f9a78e0eSmrg
163f9a78e0eSmrg private:
164*0a307195Smrg /// @cond undocumented
165b1e83836Smrg regex_error(error_type __ecode, const char* __what)
166f9a78e0eSmrg : std::runtime_error(__what), _M_code(__ecode)
167f9a78e0eSmrg { }
168f9a78e0eSmrg
169b1e83836Smrg [[__noreturn__]]
170b1e83836Smrg friend void
171b1e83836Smrg __throw_regex_error(error_type __ecode __attribute__((__unused__)),
172b1e83836Smrg const char* __what __attribute__((__unused__)))
173b1e83836Smrg { _GLIBCXX_THROW_OR_ABORT(regex_error(__ecode, __what)); }
174*0a307195Smrg /// @endcond
17548fb7bfaSmrg };
17648fb7bfaSmrg
177b1e83836Smrg /// @cond undocumented
17848fb7bfaSmrg
179b1e83836Smrg [[__noreturn__]]
18048fb7bfaSmrg void
18148fb7bfaSmrg __throw_regex_error(regex_constants::error_type __ecode);
18248fb7bfaSmrg
183b1e83836Smrg [[__noreturn__]]
184f9a78e0eSmrg inline void
185b1e83836Smrg __throw_regex_error(regex_constants::error_type __ecode, const char* __what);
186b1e83836Smrg
187b1e83836Smrg /// @endcond
188b1e83836Smrg
189b1e83836Smrg ///@} // group regex
190f9a78e0eSmrg
19148fb7bfaSmrg _GLIBCXX_END_NAMESPACE_VERSION
19248fb7bfaSmrg } // namespace std
193