我尝试使用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 ++ 20