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?
No you can`t.
A SEGFAULT isn't a regular exception.
SEGFAULT
The code you show is simply undefined behavior, and anything may be happen. There's no guarantee it ends up throwing an exception.
2.1m questions
2.1m answers
60 comments
57.0k users