I want to do something more useful with assert
than just abort
ing, that includes flushing some open files, and printing the stack trace.
I read a few articles on assert such as Assertions by Andrei Alexandrescu which talks about how to implement assertions. However I want to replace the assert handler by my own even in third party libraries which are used by my program. I understand most (but not all) compilers (gcc, MSVC, clang) & libraries (Qt,boost) which I use has options to set user defined assert handler. However at present I am not interested to have Abort,Retry,Ignore
feature for the assert, and so not looking to my code in compiler/library specific assert handler.
As I understand, assert
calls abort
which sends SIGABRT
signal, can I trap this signal and do the useful tasks?