Edit

Share via


regex_error Class

Reports a bad basic_regex object.

Syntax

class regex_error
: public std::runtime_error

Remarks

The class describes an exception object thrown to report an error in the construction or use of a basic_regex object.

Constructors

Constructor Description
regex_error Constructs the object.

Member functions

Member function Description
code Returns the error code.

Requirements

Header: <regex>

Namespace: std

Example

// 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

Returns the error code.

regex_constants::error_code code() const;

Remarks

The member function returns the value that was passed to the object's constructor.

regex_error::regex_error

Constructs the object.

regex_error(regex_constants::error_code error);

Parameters

error
The error code.

Remarks

The constructor constructs an object that holds the value error.

See also

<regex>
regex_constants Class
<regex> functions
regex_iterator Class
<regex> operators
regex_token_iterator Class
regex_traits Class
<regex> typedefs