SysTutorials

Linux Manual Pages › Section 3

stdregex_error(3)

std::regex_error – std::regex_error

Synopsis

Defined in header <regex>
class regex_error; (since C++11)
Defines the type of exception object thrown to report errors in the regular expressions library.
 std-regex error-inheritance.svg
Inheritance diagram

Member functions

              constructs a regex_error object
constructor (public member function)
              gets the std::regex_constants::error_type for a regex_error
code (public member function)

Inherited from std::exception

Member functions

destructor destroys the exception object
             (virtual public member function of std::exception)
[virtual]

what returns an explanatory string
             (virtual public member function of std::exception)
[virtual]

Example

// Run this code

#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() << '
';
        if (e.code() == std::regex_constants::error_brack) {
            std::cout << "The code was error_brack
";
        }
    }
}

Possible output:

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