1

我正在尝试基于 boost::exception 制作一个通用的异常框架。为此,我使用这样的宏:

#define AR_THROW_EXCEPTION(internalMessage)\
BOOST_THROW_EXCEPTION(boost::enable_current_exception(ArException())\
<< internal_message(internalMessage)\
<< inner_exception(boost::current_exception()))

我的问题是“boost::current_exception()”如果不是从 catch 块中调用,它将终止我的程序。为了避免定义第二个宏“AR_RETHROW_EXCEPTION”,我希望能够做到

#define AR_THROW_EXCEPTION(internalMessage)\
BOOST_THROW_EXCEPTION(boost::enable_current_exception(ArException())\
<< internal_message(internalMessage)\
if (IS_IN_CATCH_BLOCK)\
<< inner_exception(boost::current_exception()))

有人知道方法吗?

4

0 回答 0