定义于头文件
<regex>
|
||
class regex_error;
|
(C++11 起) | |
定义抛出的异常对象类型,以报告正则表达式库中的错误。
目录 |
构造 regex_error 对象 (公开成员函数) |
|
获得 regex_error 的 std::regex_constants::error_type (公开成员函数) |
[虚]
|
析构该异常对象 ( std::exception 的虚公开成员函数)
|
[虚]
|
返回解释性字符串 ( std::exception 的虚公开成员函数)
|
#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"; } } }
输出:
regex_error caught: The expression contained mismatched [ and ]. The code was error_brack