Namespaces
Variants
Views
Actions

std::regex_error

From cppreference.com
< cpp‎ | regex
Revision as of 16:13, 18 January 2013 by Nate (Talk | contribs)

Defined in header <regex>
class regex_error : public std::runtime_error {

  public:
    explicit regex_error(std::regex_constants::error_type ecode);
    std::regex_constants::error_type code() const;

};
(since C++11)

Defines the type of exception object thrown to report errors in the regular expressions library.

Contents

Member functions

Template:cpp/regex/regex error/dcl list regex errorTemplate:cpp/regex/regex error/dcl list code

Inherited from std::exception

Member functions

[virtual]
destructs the exception object
(virtual public member function of std::exception) [edit]
[virtual]
returns an explanatory string
(virtual public member function of std::exception) [edit]

Example

#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";
        }
    }
}

Output:

regex_error caught: The expression contained mismatched [ and ].
The code was error_brack