std::regex_error
来自 cppreference.cn
定义于头文件 <regex> |
||
class regex_error; |
(自 C++11 起) | |
定义为报告正则表达式库中错误而抛出的异常对象类型。
继承关系图
目录 |
[编辑] 成员函数
构造一个 regex_error 对象(公有成员函数) | |
替换 regex_error 对象(公有成员函数) | |
获取 regex_error 的 std::regex_constants::error_type(公有成员函数) |
继承自 std::exception
成员函数
[虚拟] |
销毁异常对象 ( std::exception 的虚公有成员函数) |
[虚拟] |
返回解释性字符串 ( std::exception 的虚公有成员函数) |
[编辑] 示例
运行此代码
#include <iostream> #include <regex> 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