kamziro kamziro - 7 months ago 73
C++ Question

Intercepting c++ exceptions

So my c++ program just crashed, and the error I got was:

terminate called after throwing an instance of 'std::length_error'
what(): basic_string::_S_create

Now, what I've added recently to my code is a SIGSEGV handler, so if it was a segmentation fault, it would proceed to print the stack trace.

How do I go about making an exit handler for uncaught (or more like uncatchable) exceptions in c++?


Use set_terminate function which sets the terminate handler function:

A terminate handler function is a function automatically called when the exception handling process has to be abandoned for some reason. This happens when a handler cannot be found for a thrown exception, or for some other exceptional circumstance that makes impossible to continue the handling process.