Is it possible to catch a segfault with try/catch?

c++, try-catch

Solution

No you can`t.

A `SEGFAULT` isn't a regular exception.

The code you show is simply undefined behavior, and anything may be happen. There's no guarantee it ends up throwing an exception.

Problem

I did this test to see what happened: ``` try { int *x = 0; *x = 1234; } catch(...) { cout << "OK"; } ``` But it throws a segfault, why does it not catch the segfault?

Original source