Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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
Aborted

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++?

like image 842
kamziro Avatar asked May 23 '26 22:05

kamziro


1 Answers

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.

like image 65
vitaut Avatar answered May 26 '26 12:05

vitaut



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!