c++ - Why is std::terminate handler not called if exceptions are disabled? - Stack Overflow

The default std::terminate_handler calls std::abort. std::terminate is called in the case of an unhandl

The default std::terminate_handler calls std::abort. std::terminate is called in the case of an unhandled exception, or it can be called manually.

If I provide a terminate handler then it's only called if exceptions are enabled, but I don't see why this should be the case, and there's nothing in the documentation about it being disabled when exceptions are disabled. I don't see the connection between the terminate handler and exceptions, or why it's required. The terminate handler says "do this before aborting".

I don't know why it's disabled with exceptions disabled. Here is a question I asked earlier about this happening to me, and here is a reproducible example I made that shows that the terminate handler is no longer called when exceptions are disabled.

The above is the case on MSVC, and I don't know if it happens also with other compilers.

There is a question from 2018 that says:

std::terminate with disabled exceptions (MSVC implementation)

As it turns out, msvc has dummy implementation for terminate function when _HAS_EXCEPTIONS macro is not set:

    inline void __CRTDECL terminate() _NOEXCEPT
    {   // handle exception termination
    }

So it's just the case with MSVC, but is this still the case in 2025? That std::terminate is just an empty function when exceptions are disabled?

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744645004a4585562.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信