Movatterモバイル変換


[0]ホーム

URL:


cppreference.com
Namespaces
Variants
    Actions

      std::regex_error

      From cppreference.com
      <cpp‎ |regex
       
       
       
      Regular expressions library
      Classes
      (C++11)
      Algorithms
      Iterators
      Exceptions
      regex_error
      (C++11)
      Traits
      Constants
      (C++11)
      Regex Grammar
       
       
      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

      Contents

      [edit]Member functions

      constructs aregex_error object
      (public member function)[edit]
      replaces theregex_error object
      (public member function)[edit]
      gets thestd::regex_constants::error_type for aregex_error
      (public member function)[edit]

      Inherited fromstd::runtime_error


      Inherited fromstd::exception

      Member functions

      [virtual]
      destroys the exception object
      (virtual public member function ofstd::exception)[edit]
      [virtual]
      returns an explanatory string
      (virtual public member function ofstd::exception)[edit]

      [edit]Example

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

      Possible output:

      regex_error caught: The expression contained mismatched [ and ].The code was error_brack
      Retrieved from "https://en.cppreference.com/mwiki/index.php?title=cpp/regex/regex_error&oldid=153021"

      [8]ページ先頭

      ©2009-2025 Movatter.jp