+ 1

What's happening in this program? Is it crashing or is it throwing an error? [Code in description]

#include <iostream> class A { public: A() {} ~A() { throw 42; } }; int main(int argc, const char * argv[]) { try { A a; throw 32; } catch(int a) { std::cout << a; } } What's difference between crashing and error?

27th Feb 2021, 10:34 AM
Mahima Rajvir Singh
Mahima Rajvir Singh - avatar
3 odpowiedzi
+ 5
I tried your code and saw the error message mentioned something about C++11 destructor defaults to 'noexcept'. I'm guessing that means destructor by default shouldn't throw exception (cmiiw in case of wrong interpretation) http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2010/n3166.html
27th Feb 2021, 12:41 PM
Ipang
+ 2
a crash often result from an error (most likely logical one) an error not systematically induce a crash (syntax and predictible errors are catched and program kindly stop at worst case, with error message if catched error not handled)
27th Feb 2021, 12:05 PM
visph
visph - avatar