4 ms·
`class exception1 {}; class exception2 {}; try { ... if (condition1) throw my_exception1 (); ... if (condition2) throw my_excep
by cgrealy 4y ago
`class exception1 {};
class exception2 {};
try {
...
if (condition1)
throw my_exception1 ();
...
if (condition2)
throw my_exception2 ();
...
}
catch (my_exception1 &e) {
handle_exception1 ();
}
catch (my_exception2 &e) {
handle_exception2 ();
}`
He posts this as an example of why C++ sucks.
Yeah, but no one actually writes code like that. The whole point of exceptions is for situations where you cannot handle the error locally. If you’re throwing and catching exceptions in the same method, you’re doing it wrong.