以编程方式确定是否启用异常 [英] Programmatically determine whether exceptions are enabled

查看:104
本文介绍了以编程方式确定是否启用异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大多数C ++编译器允许禁用异常。有没有办法从代码中确定它,而不使用特定于编译器的预处理器宏,例如用于MSVC的_CPPUNWIND?

解决方案

由于 2014年的WG21 ,有一个推荐的宏使用

  __ cpp_exceptions 

如果支持异常,它将具有值为199711的值编译器符合C ++ 98。其他类似功能宏在此显示


Most C++ compilers allow for exceptions to be disabled. Is there a way to determine it from the code without using compiler-specific preprocessor macros, such as _CPPUNWIND for MSVC? Ideally at compile time.

解决方案

Since WG21 in 2014, there is a recommended macro to use

__cpp_exceptions

It will have the value 199711 if exceptions are supported and the compiler conforms to C++98. Other similar feature macros are shown here.

这篇关于以编程方式确定是否启用异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆