0

次の例は、チュートリアルからのものです。実行すると、例外がスローされてからコアダンプがスローされます。次のように、catch() を使用して例外をキャッチし、コアダンプを回避しようとしています。

しかし、うまくいきません。助言がありますか?

ありがとう

-トッド

---- コアダンプ メッセージ BEGIN---

のインスタンスをスローした後に呼び出される終了

'boost::exception_detail::clone_impl >'

what(): 繰り返し演算子 " " は正規表現を開始できません。正規表現の解析中にエラーが発生しました: '>>>HERE>>> '.

中止 (コアダンプ)

- - 終わり - -

--- プログラム開始 ----

#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");

 } 

- - 終わり -

4

1 に答える 1

1

boost::regex()例外をスローしているのはのコンストラクターです。

boost::regex e(regx);

それをブロック内に置くと、例外ハンドラーtryによってキャッチされます。boost::regex_error&

于 2012-03-16T08:17:30.563 に答える