简体   繁体   中英

Why do I get a coredump when I try to catch an exception from boost::regex_match(text, e)?

The following example is from the tutorial. When I run it, it throws exception and then coredump. I try to use catch() to catch the exception to avoid coredump like the following:

But it doesn't work. any suggestions?

Thanks

-Todd

---- coredump message BEGIN---

terminate called after throwing an instance of

'boost::exception_detail::clone_impl >'

what(): The repeat operator " " cannot start a regular expression. The error occured while parsing the regular expression: '>>>HERE>>> '.

Abort (core dumped)

---- END---

--- program BEGIN ----

#include <boost/regex.hpp>
#include <iostream>
    void print_captures(const std::string& regx, const std::string& text)

    {

    boost::regex e(regx);

   boost::smatch what;

   std::cout << "Expression:  \"" << regx << "\"\n";

   std::cout << "Text:        \"" << text << "\"\n";

   try {

     //     boost::regex_match(text, what, e, boost::match_extra);

     boost::regex_match(text, e);

   }

   **catch(boost::regex_error& e) {

std::cout <<"!!!!\n"; 

   } 

   catch (...) {

     std::cout << "###\n"; 

   }** 



}


int main(int , char* [])

{
  print_captures("*", "AAA");

 } 

---- END --

It is the constructor of boost::regex() that is throwing the exception:

boost::regex e(regx);

Put the it inside the try block and it will be caught by the boost::regex_error& exception handler.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM