我正在使用boost 1.53.0,並且直到現在都沒有問題(並且使用了套接字,定時器,容器,算法,所有這些都沒有問題)。BOOST_THROW_EXCEPTION導致無限遞歸
我喜歡使用增強異常的想法,特別是因爲行號和不行。
然而,在我的(超級簡單)的代碼:通過CMake生成
#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_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:「助推:: 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(贏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);
#line 92「C:\ devtools \ boost_1_53_0 \ boost/throw_exception.hpp」 }
你能給一個完整的最小工作的例子,包括頭文件等? –