To view parent comment, click here.
To read all comments associated with this story, please click here.
It's your coworker fault, and actually C++ notifying you that programming error is a feature
. Throwing exceptions in a C++ destructor it's generally a bad programming practice (exceptions thrown in Java finalizers are simply ignored, that should give you an idea).
http://www.parashift.com/c++-faq-lite/exceptions.html#faq-17.3
OTOH, throwing E1 in a finally block during stack unwinding, will swallow E2 silently. You'll end up handling (or maybe ignoring) an exception that it's not the cause your code doesn't work.
public class Main {
void doSomething() throws Exception {
throw new Exception("i know why it does not work");
}
void throwIt() {
throw new RuntimeException("i have no idea why it does not work");
}
void run() throws Exception {
try {
doSomething();
} finally {
throwIt();
}
}
public static void main(String[] args) throws Exception {
new Main().run();
}
}
C++ job is far better pointing you bad exception handling than Java.






Member since:
> Can you describe, what's wrong with C++ exceptions? And why Java exceptions are unproblematic compared to them?
Nested exceptions? A nightmare. For example,
class A {
public:
A() { ... }
~A() { if (C1) throw E1; }
...
}
void foo()
{
A a;
...
if (C2)
throw E2;
}
if condition C2 is true, then exception E2 is thrown, and this causes A's destructor to be called while the excepting is "unwinding" the call stack. If condition C1 in A's destructor is also true, then... KABOOM!!! Your application dies hard :-)
There's a large C++ application written (by someone else at my company) with these pitfalls. It has been a nightmare to fix these issues.
Regards,
Carlos