Following code will compile but crash at run time:
int main() {
try {
throw;
}
catch(...){
cout<<"In catch";
}
return 0;
}
Result: “Unhandled exception at 0x7c812a5b in hello.exe: Microsoft C++ exception: [rethrow] @ 0x00000000”
Why compiler allows the code to compile? it looks not so difficult job for compiler to check if this code is part of catch block or not.
From C++ Standard (15.1.8)
If no exception is presently being handled, executing a throw-expression with no operand calls std::terminate()
As standard allows it and gives clear semantics, a compiler can only conform to it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With