Intel® C++ Compiler
Community support and assistance for creating C++ code that runs on platforms based on Intel® processors.

Floating point signals into C++ exceptions

velvia
Beginner
488 Views

Hi,

Is there a way, using intel C++ compiler, to transform a floating point exception into a regular exception that one can catch ?

Francois

0 Kudos
3 Replies
KitturGanesh
Employee
488 Views

Hi, 
You can try the "fnon-call-exceptions" option which should allow trapping of SIGFPE signals. You can then catch that with your signal handler to throw a regular C++ exception....
_Kittur

0 Kudos
velvia
Beginner
488 Views

Hi Kittur,

Thanks for your help. Do you have any tutorial on how to write the signal handler? I've never done such a thing and I can't find anything on the internet. I just found this article that deals with fortran: https://software.intel.com/en-us/node/510891 .

By the way, can you handle those signals on Windows too?

0 Kudos
KitturGanesh
Employee
488 Views

Thanks for your help. Do you have any tutorial on how to write the signal handler? I've never done such a thing and I can't find anything on....

Nope, other than the samples given on the Fortran link you show there's no other tutorial that I am aware of.  On Windows*, the OS provides exception handling using SEH (Structured exception handling) but the compiler doesn't include extensions for SEH support except it uses the built-in exception handling mechanism. On the other hand, on Linux the libstdc++ provides the exception handling capability. As such note that there's no fnon-call-exceptions option for Windows in the compiler. That said, basically you can write a signal handler to catch a signal and throw an exception. An exception can be thrown inside the try block() and can be handled within a catch block accordingly. BTW, googling on SIGFPE exception handling example shows quite a few results that pretty much show the generic template code for a generic signal handler function that should help (such as: http://www.cplusplus.com/doc/tutorial/exceptions/", "http://www.yolinux.com/TUTORIALS/C++Signals.html" and so on... Also, the fortran examples link you show also uses similar template (try/catch blocks)

_Kittur

.

0 Kudos
Reply