I have this code:
#include <iostream>
#include <exception>
class TestException : public std::exception
{
public:
char const* what() const throw() override { return msg_.c_str(); }
protected:
std::string & message() throw() { return msg_; }
private:
std::string msg_;
};
void ThrowIt()
{
throw TestException();
}
int main()
{
ThrowIt();
}
Running this when built in either Release or Debug on Windows compiled with Visual Studio results in program termination, same goes for when compiled with GCC on a Linux machine, the result is :
terminate called after throwing an instance of 'TestException'
what(): Aborted
Both terminate the program once an unhandled exception is caught. Is this behaviour strictly system specific or is this specified by the standard? Is there a cross-platform way that I can reroute every exception not handled by catch
to a handler instead of just terminating the program?
Aucun commentaire:
Enregistrer un commentaire