+ 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?
3 Antworten
+ 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
+ 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)