Cpp exceptions
From wikinotes
C++ comes with an exception system, but it is not quite as convenient as the python exception system.
Usage
TODO:
I need to test this out and see if I can define my own exceptions that come bundled with a type, and a provided description of the error.
// exception inheriting from exception class InvalidIdError: public exception { virtual const char* what() const throw() { return "My Exception"; } } // empty classes may also be used as exceptions class MyException; try { throw InvalidId; } catch (exception& e) { cout << e.what() << endl; } catch(...) { cout << "unknown exception occurred" << endl; }multiple catches
try { } catch( MyExcept, const& e ){ } catch( MyOtherExcept, const& e ){ }re-throw exceptions
try { } catch( MyExcept, const& e ){ throw; // throw without arguments re-throws the last exception }