Catch Segfault or any other errors/exceptions/signals in C++ like catching exceptions in Java

You cannot reliably resume execution after a segmentation violation. If your program must remain running, fence off the offending library in a separate process and communicate with it over a pipe. When it takes a segmentation violation, your program will notice the closed pipe.


Unfortunately, you cannot make the program continue. The buggy code that resulted in SIGSEGV usually triggers undefined behaviour like dereferencing a null pointer or reading garbage memory. You cannot possibly continue if your code operates on invalid data.

You can handle the signal, but the most you can do is dump the stack trace and die.

C and C++ are inherently unsafe, you cannot handle errors triggered by undefined behaviour and let the program continue.


You can use signal handlers. It's not really recommended though because you can't guarantee that you've eliminated the cause of the problem. The best thing to do would be to isolate it in a separate process- this is the approach Google Chrome takes.

If it's FOSS, the easiest thing to do would be to just debug it.