C++ BOOST\u THROW\u异常导致无限递归

C++ BOOST\u THROW\u异常导致无限递归,c++,exception,boost,C++,Exception,Boost,我使用的是Boost1.53.0,到目前为止还没有出现任何问题(并且使用了套接字、计时器、容器、算法,所有这些都没有问题) 我喜欢使用boost异常的想法,尤其是因为行号之类的原因 但是,在我的(超级简单)代码中: BOOST\u THROW\u异常进入无限递归,而不是抛出 编译器甚至捕捉到这一点,并声明编译器警告 警告C4717:“boost::exception\u detail::throw\u exception\”:在所有控制路径上递归,函数将导致运行时堆栈溢出 它一直在打: test

我使用的是Boost1.53.0,到目前为止还没有出现任何问题(并且使用了套接字、计时器、容器、算法,所有这些都没有问题)

我喜欢使用boost异常的想法,尤其是因为行号之类的原因

但是,在我的(超级简单)代码中:

BOOST\u THROW\u异常进入无限递归,而不是抛出

编译器甚至捕捉到这一点,并声明编译器警告

警告C4717:“boost::exception\u detail::throw\u 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++
编辑并添加扩展宏:

看起来宏扩展为

 ::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);
扩展到

 ::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\u 1\u 53\u 0\boost/throw\u exception.hpp”
}

这太奇怪了。正如您可以在boost::exception::throw\u轻松检查的那样,exception\u根本不是递归的

我能看到这种事情发生的唯一方法就是使用邪恶的宏。请尝试在每个include指令之前和之后将其放入主文件中

#if defined(throw_exception) || defined(throw_exception_)
#error Somebody set us up the bomb
#endif

好吧,看来是出于某种原因

    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)));
    }

在我的代码中…所以我一定破坏了我自己的boost构建。对不起,这是白费力气!我投票关闭了这个线程…

boost::throw\u异常很好,但是它没有添加行信息等。给我带来问题的是BOOST\u THROW\u异常宏。无限循环位于“exception\u detail::throw\u exception\u”中。它调用另一个BOOST\u THROW\u异常。我将扩展宏并将其添加到我的问题中,这样我们就可以清楚地看到问题。此外,我应该声明,我确认没有人“为我们制造炸弹”。我将继续回答,并给你评分,因为“你打破了某些东西”实际上已经过时了。你能给出一个完整的最小工作示例,包括头文件等吗。?
    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)));
    }