开发者

Disable Exceptions in BOOST?

开发者 https://www.devze.com 2022-12-13 12:53 出处:网络
I want to use boost::asio but I don\'t want boost to throw exceptions, because in my environment exceptions must not be raised.

I want to use boost::asio but I don't want boost to throw exceptions, because in my environment exceptions must not be raised.

I've encountered BOOST_NO_EXCEPTIONS but the documentation says that callers of throw_exception can assume that this function never returns. But how can a user supplied function not return? What replacement function would I need to insert here? Do I have to terminate the process in case boost code wants to thro开发者_开发百科w an exception?


Well, what do you want to do on error condition? BOOST_NO_EXCEPTION does not magically make Boost source code use alternative mechanism of propagating error back to callers. So, you either print an error to stderr and die, or you longjmp all the way to the top -- leaking whatever resources the functions presently on the call stack might have allocated.


Either you terminate the process or you goto a something like a global error handler using longjmp which you've previously defined with setjmp.


You seemed to have misunderstood the meaning of BOOST_NO_EXCEPTIONS, it only gives you a chance to bailout in the way you desire in a consistent manner.

The execution has entered a state where it can no more proceed, that is when exception is thrown, so if the user defined throw_exception returns then it is logical to think that the behavior is undefined.

0

精彩评论

暂无评论...
验证码 换一张
取 消