Converting floating point exceptions into C++ exceptions

前端 未结 5 888
栀梦
栀梦 2021-02-06 08:41

Is it possible to convert floating point exceptions (signals) into C++ exceptions on x86 Linux?

This is for debugging purposes, so nonportability and imperfection is oka

5条回答
  •  我在风中等你
    2021-02-06 09:20

    Due to the way signals and exceptions work, you can't do it immediately when the signal is thrown - exceptions rely on certain aspects of the stack that aren't true when a signal handler gets called.

    You can set a global variable in the signal handler, and then check this at key points in the program and throw an exception if it's set. This doesn't give you the exact information about the thrown exception, though.

提交回复
热议问题