What is the most correct way to throw and catch an exception?
Is that good enough? (I think it is the best method because you can delete your exception after you've gotten what you need. Correct me if I'm wrong.)Code:class Exception; // Has a getMessage() method and a few constructors. void doSomething(void) { throw new Exception("You're screwed."); } #include <iostream> void main(void) { try { doSomething(); } catch (Exception *e) { std::cerr << e->getMessage() << std::endl; } }
Or should I perhaps throw it like this:
And catch it either by reference:Code:throw Exception("You're screwed.");
Or by value:Code:catch (Exception &e)
I'd like to hear your opinions.Code:catch (Exception e)




Reply With Quote