regex_error 类
报告错误的 basic_regex 对象。
语法
class regex_error
: public std::runtime_error
备注
该类描述一个异常对象,引发该异常的目的是为报告一个构造中的错误或 basic_regex
对象的使用错误。
构造函数
构造函数 | 说明 |
---|---|
regex_error | 构造 对象。 |
成员函数
成员函数 | 说明 |
---|---|
code | 返回错误代码。 |
要求
标头:<regex>
命名空间: std
示例
// std__regex__regex_error.cpp
// compile with: /EHsc
#include <regex>
#include <iostream>
int main()
{
std::regex_error paren(std::regex_constants::error_paren);
try
{
std::regex rx("(a");
}
catch (const std::regex_error& rerr)
{
std::cout << "regex error: "
<< (rerr.code() == paren.code() ? "unbalanced parentheses" : "")
<< std::endl;
}
catch (...)
{
std::cout << "unknown exception" << std::endl;
}
return (0);
}
regex error: unbalanced parentheses
regex_error::code
返回错误代码。
regex_constants::error_code code() const;
注解
成员函数将返回传递给对象的构造函数的值。
regex_error::regex_error
构造 对象。
regex_error(regex_constants::error_code error);
参数
error
错误代码。
备注
构造函数将构造一个保留 error 值的对象。
另请参阅
<regex>
regex_constants 类
<regex> 函数
regex_iterator 类
<regex> 运算符
regex_token_iterator 类
regex_traits 类
<regex> typedefs
反馈
https://aka.ms/ContentUserFeedback。
即将发布:在整个 2024 年,我们将逐步淘汰作为内容反馈机制的“GitHub 问题”,并将其取代为新的反馈系统。 有关详细信息,请参阅:提交和查看相关反馈