名稱空間
變體
操作

std::regex_error

來自 cppreference.com
< cpp‎ | regex
在標頭檔案 <regex> 中定義
class regex_error;
(C++11 起)

定義用於報告正則表示式庫中錯誤的異常物件型別。

cpp/error/exceptioncpp/error/runtime errorstd-regex error-inheritance.svg

繼承圖

目錄

[編輯] 成員函式

構造一個 regex_error 物件
(公有成員函式) [編輯]
替換 regex_error 物件
(公有成員函式) [編輯]
獲取 regex_errorstd::regex_constants::error_type
(公有成員函式) [編輯]

繼承自 std::runtime_error


繼承自 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