Exception catch all statement
Jan 19, 2012 at 3:38pm UTC
Hey guys. When using catch(...) to handle unexpected exceptions, is there a way to obtain a handle to the exception that was thrown so that I can call the "what()" function on it to get a description?
1 2 3 4 5 6 7 8
class exception {
public :
exception () throw ();
exception (const exception&) throw ();
exception& operator = (const exception&) throw ();
virtual ~exception() throw ();
virtual const char * what() const throw ();
}
Kind regards.
Jan 19, 2012 at 4:07pm UTC
It sounds like you want to catch a std::exception& instead of all exceptions.
1 2 3 4 5 6 7 8
try
{
// code that can throw
}
catch (std::exception& e)
{
std::cout << e.what() << std::endl;
}
This will catch all instances of std::exception and instances of classes that inherit from std::exception.
Jan 19, 2012 at 4:33pm UTC
Topic archived. No new replies allowed.