Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All

regex_error::code

Returns the error code.

regex_constants::error_code code() const;

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

 

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

Header: <regex>

Namespace: std

Community Additions

ADD
Show:
© 2015 Microsoft