New to cpp. When I call to erase on iterator without increment it my program exit immediately without any sign or crash. In the following example only 'After if condition ' is printed and than nothing. no error displayed. however if i do the correct call to list.erase(it++); than it print all. my question is about what happened when I don't call it correct. why i don't see any crash or exit? My worried and the reason that i asked the question is about catching these kind of crashes, why i didn't catch it in the catch block? is there a way to catch it?
int main(int argc, char *argv[]) {
try {
list<int>::iterator it;
list<int> list;
list.push_back(1);
for (it = list.begin(); it != list.end(); ++it) {
if ((*it) == 1) {
list.erase(it);
}
cerr << "After if condition " << endl;
}
cerr << "After for condition" << endl;
} catch (...) {
cerr << "catch exception" << endl;
}
cerr << "Finish" << endl;
}