My code compiled as a Windows DLL with Visual C ++. I want to register rare cases when terminate() is called, so I set the terminate() handler to the library initialization function, and the latter is called by the user code before using my library. My handler writes to the log and calls abort() , emulating the default behavior of terminate() .
The problem is that the user code can also be written in C ++ and use the same version of C ++ execution and thus share the terminate() handler with my library. This code may also want to modify the terminate() handler for logging. So they will call set_terminate() , then load and initialize my library, and my library will also call set_terminate() and override their terminate() handler, and it will be very difficult to detect, because the terminate() handler is the last thing they will check , I believe.
So, I want the following. Inside the library initialization function, I retrieve the current terminate() handler , find if it is standard, and if it is non-standard, I will save its address and later (if necessary) my terminate() handler will write to the log and then redirect the call to this user terminate() handler.
Is it possible to determine whether the terminate() handler is currently installed, by default or custom?
source share