std::regex_error
| Defined in header <regex> |  |  | 
|---|---|---|
| class regex_error; |  | (since C++11) | 
定义抛出的异常对象类型以报告正则表达式库中的错误。
二次
二次
继承图
成员函数
| (constructor) | constructs a regex_error object (public member function) | 
|---|---|
| code | gets the std::regex_constants::error_type for a regex_error (public member function) | 
继承自STD:例外
成员函数
| (destructor) virtual | destructs the exception object (virtual public member function of std::exception) | 
|---|---|
| what virtual | returns an explanatory string (virtual public member function of 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二次
 © cppreference.com在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。
本文档系腾讯云开发者社区成员共同维护,如有问题请联系 cloudcommunity@tencent.com

