As stated in the glog whitepaper, you can use
Custom Failure Function
to replace the default behavior of exit ().
Example:
void YourFailureFunction() { throw exception(); } int main(int argc, char* argv[]) { google::InstallFailureFunction(&YourFailureFunction); }
However, the function is called in the destructor, so the behavior may not correspond to our needs. In my situation, the function is called twice, and I need to implement a not-so-beautiful hack to throw an exception two times.
bool alreadyThrown = false; void YourFailureFunction() { if (!alreadyThrown) { alreadyThrown = true; throw exception(); } }
source share