Why do I have core dump in this code I see output
Catch
terminate called after throwing an instance of 'std::runtime_error'
what(): ZERO DIV
Aborted (core dumped)
But I expect
Catch
terminate called after throwing an instance of 'std::runtime_error'
what(): ZERO DIV
My code
class Q {
public:
Q(int a, int b) try
: val(b != 0 ? a / b : throw runtime_error("ZERO DIV"))
{
cout << "Q()" << endl;
}
catch(...)
{
cout << "Catch " << endl;
val = nullopt;
}
~Q() {
cout << "~Q()" << endl;
}
private:
optional<int> val;
};
int main() {
Q q = {1, 0};
return 0;
}
I think that the reason of core dump is execution of a / b, but I shouldn't be executed, because b is not zero