Namespaces
Variants

std:: regex_error

From cppreference.net
Regular expressions library
Classes
(C++11)
Algorithms
Iterators
Exceptions
regex_error
(C++11)
Traits
Constants
(C++11)
Regex Grammar
ヘッダーで定義 <regex>
class regex_error ;
(C++11以降)

正規表現ライブラリでエラーを報告するためにスローされる例外オブジェクトの型を定義します。

cpp/error/exception cpp/error/runtime error std-regex error-inheritance.svg

継承図

目次

メンバー関数

regex_error オブジェクトを構築する
(public member function)
regex_error オブジェクトを置換する
(public member function)
regex_error std::regex_constants::error_type を取得する
(public member function)

std::exception から継承

メンバ関数

例外オブジェクトを破棄する
( std::exception の仮想公開メンバ関数)
[virtual]
説明文字列を返す
( 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