Defined in header <regex> | ||||
---|---|---|---|---|
| (since C++11) |
Defines the type of exception object thrown to report errors in the regular expressions library.
Inheritance diagram.
Member functions
constructs a regex_error object (public member function) | |
gets the std::regex_constants::error_type for a regex_error (public member function) |
Inherited from std::exception
Member functions
(destructor)
[virtual] | destructs the exception object (virtual public member function of std::exception ) |
[virtual] | returns an explanatory string (virtual public member function of std::exception ) |
Example
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | #include <regex> #include <iostream> int main() { try { std::regex re( "[a-b][a" ); } catch ( const std::regex_error& e) { std::cout << "regex_error caught: " << e.what() << '\n' ; if (e.code() == std::regex_constants::error_brack) { std::cout << "The code was error_brack\n" ; } } } |
Output:
1 2 | regex_error caught: The expression contained mismatched [ and ]. The code was error_brack |
Please login to continue.