我如何抛出文件和行号错误?

问题描述 投票:1回答:1

我尝试使用BOOST_THROW_EXCEPTION执行此操作,这里是example

#include <boost/throw_exception.hpp>
#include <stdexcept>
void demo_boost_throw()
{
    BOOST_THROW_EXCEPTION(std::runtime_error("boost throw std exception."));
    }
int main() {
    demo_boost_throw();
    return 0;
}

here我们可以看到它确实包含文件

#define BOOST_THROW_EXCEPTION(x)\
        ::boost::throw_exception( ::boost::enable_error_info(x) <<\
        ::boost::throw_function(BOOST_THROW_EXCEPTION_CURRENT_FUNCTION) <<\
        ::boost::throw_file(__FILE__) <<\
        ::boost::throw_line((int)__LINE__) )

但是当我运行程序时,它不会打印出文件和行。

current_exception_diagnostic_information(),但这需要捕捉并打印。我不想抓住它。我希望e.what()包含throw_function,throw_file和throw_line的额外信息。我该怎么办?

c++ boost
1个回答
0
投票

如果您有机会访问C ++ 20

© www.soinside.com 2019 - 2024. All rights reserved.