Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Programmatically determine whether exceptions are enabled

Tags:

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.

like image 551
Nemanja Trifunovic Avatar asked Jun 26 '11 22:06

Nemanja Trifunovic


2 Answers

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.

like image 173
Mark Lakata Avatar answered Oct 19 '22 12:10

Mark Lakata


No. Exceptions are part of C++. The fact that some compilers allow you to disable them is quite irrelevant and the Standard will not provide for you to detect if they're enabled- as far as it's concerned, they're always enabled. If you want to know about implementation-specific behaviour, the only way to go is to ask the implementation.

like image 24
Puppy Avatar answered Oct 19 '22 14:10

Puppy