std::regex_error

定义于头文件 <regex>
class regex_error;
(C++11 起)

定义抛出的异常对象类型,以报告正则表达式库中的错误。

cpp/error/exceptioncpp/error/runtime errorstd-regex error-inheritance.svg
关于这幅图像

继承图

目录

成员函数

构造 regex_error 对象
(公开成员函数)
获得 regex_errorstd::regex_constants::error_type
(公开成员函数)

继承自 std::exception

成员函数

析构该异常对象
(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

版本历史

  • (当前 | 先前 2017年6月16日 (五) 09:16Fruderica讨论 | 贡献. . (937字节) (-420). . (撤销)
  • 当前 | 先前 2014年10月26日 (日) 18:06P12bot讨论 | 贡献 . . (1,357字节) (0). . (Fix some translations) (撤销)
  • 当前 | 先前 2013年7月2日 (二) 11:13P12bot讨论 | 贡献 . . (1,357字节) (-40). . (Use {{lc}}. Update links. Various fixes.) (撤销)
  • 当前 | 先前 2012年11月2日 (五) 11:57P12bot讨论 | 贡献 . . (1,397字节) (+233). . (r2.7.3) (机器人添加:de, en, es, fr, it, ja, pt, ru) (撤销)
  • 当前 | 先前 2012年10月27日 (六) 09:07P12讨论 | 贡献 . . (1,164字节) (0). . (1个修订: Translate from the English version) (撤销)
  • 当前 | 先前 2012年10月26日 (五) 06:00TranslationBot讨论 | 贡献. . (1,164字节) (-15). . (Translated from the English version using Google Translate) (撤销)
  • 当前 | 先前 2012年10月25日 (四) 15:33P12讨论 | 贡献 . . (1,179字节) (0). . (1个修订: Translate from the English version) (撤销)
  • 当前 | 先前) 2012年10月25日 (四) 12:00TranslationBot讨论 | 贡献. . (1,179字节) (+1,179). . (Translated from the English version using Google Translate)