2

私はboost 1.53.0を使用していますが、これまで問題はありませんでした(ソケット、タイマー、コンテナ、アルゴリズムをすべてトラブルなしで使用しました)。

特に行番号などの理由から、ブースト例外を使用するというアイデアが気に入っています。

ただし、私の(非常に単純な)コードでは:

#include <iostream>
#include <fstream>

#include <boost/scoped_ptr.hpp>
#include <boost/exception/all.hpp>

struct my_error: virtual boost::exception, virtual std::exception { };

int main(int argc, char* argv[])
{
  try
  {
    BOOST_THROW_EXCEPTION(my_error());
  }
  catch(...)
  {
    std::cout <<"fail";
  }
}

CMAKE で生成されたプロジェクト (失敗しないことを願っています)

cmake_minimum_required (VERSION 2.8)
project(error_test)
IF(WIN32)
   set(Boost_USE_STATIC_LIBS ON)
   set(Boost_USE_MULTITHREADED ON) 
   set(Boost_USE_STATIC_RUNTIME OFF)
   set(Boost_NO_SYSTEM_PATHS FALSE)
ENDIF()

find_package(Boost COMPONENTS system date_time)
include_directories(${Boost_INCLUDE_DIRS}
    )



add_executable(${PROJECT_NAME} main.cpp)

target_link_libraries(${PROJECT_NAME}
${Boost_LIBRARIES})

投げる代わりに、BOOST_THROW_EXCEPTION は無限再帰に入ります!

コンパイラはこれをキャッチし、コンパイラの警告を表示します

警告 C4717: 'boost::exception_detail::throw_exception_': すべての制御パスで再帰的です。関数はランタイム スタック オーバーフローを引き起こします。

そして、それはただヒットし続けます:

test.exe!boost::exception_detail::throw_exception_<my_error>(const my_error & x, const char * current_function, const char * file, int line)  Line 84 + 0xd1 bytes  C++

Visual Studio 2010 (win 64) を使用しています。それが役立つ場合は、次のコマンドを使用してブーストを構築しました。

.\b2 install --prefix=C:\devtools\boost_1_53_0 --toolset=msvc --build-type=complete --build-dir=C:\devtools\bin\boost_1_53_0 address-model=64 architecture=x86

EDIT 拡張マクロの追加:

マクロが展開するように見えます

 ::boost::exception_detail::throw_exception_(my_error(), __FUNCSIG__  ,"main.cpp",40);

に展開します

 throw_exception_( E const & x, char const * current_function, char const * file, int line )
 {
     ::boost::exception_detail::throw_exception_(set_info( set_info( set_info( enable_error_info(x), throw_function(current_function)), throw_file(file)), throw_line(line)), __FUNCSIG__  ,"C:\\devtools\\boost_1_53_0\\boost/throw_exception.hpp",91);

#92行目 "C:\devtools\boost_1_53_0\boost/throw_exception.hpp" }

4

2 に答える 2

0

わかりました。何らかの理由で次のように見えます。

    throw_exception_( E const & x, char const * current_function, char const * file, int line )
    {
        boost::throw_exception(
            set_info(
                set_info(
                    set_info(
                        enable_error_info(x),
                        throw_function(current_function)),
                    throw_file(file)),
                throw_line(line)));
    }

に変更されました

    throw_exception_( E const & x, char const * current_function, char const * file, int line )
    {
        BOOST_THROW_EXCEPTION(
            set_info(
                set_info(
                    set_info(
                        enable_error_info(x),
                        throw_function(current_function)),
                    throw_file(file)),
                throw_line(line)));
    }

私のコードでは...だから私は自分のブーストビルドを壊したに違いありません。ワイルドグースチェイスでごめんなさい!このスレッドを閉じることに投票しました...

于 2013-06-22T14:57:55.597 に答える