I've never seen this one before, but I think that as a rule, a catch should never throw again unless it is passing it out of the method (as in "throws Exception").
try {
...
try {
...
} catch (Exception e) {
// do stuff
throw e;
}
} catch (Exception e) {
// do more stuff
}
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Never seen this before, but here is something nasty.
(Explicit use of Exception as flow-control.)
public void foo() {
try {
for (int i = 0; i < 100; i++) {
if (i == 98) throw new Exception();
}
} catch (Exception e) {}
}
Stupid example, but I think you can see the point.
Rather than putting the condition in the loop, or
using the "break", and exception is thrown to stop
the loop.
I suppose what we could do to catch this, is look
for all Try blocks which *explicitely* throws the same
exception that is being caught. (If its thrown by
a method, thats OK.)
Thoughts?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I've never seen this one before, but I think that as a rule, a catch should never throw again unless it is passing it out of the method (as in "throws Exception").
try {
...
try {
...
} catch (Exception e) {
// do stuff
throw e;
}
} catch (Exception e) {
// do more stuff
}
Yup, using exceptions as flow control... as a goto, almost. Blah.
Tom
Never seen this before, but here is something nasty.
(Explicit use of Exception as flow-control.)
public void foo() {
try {
for (int i = 0; i < 100; i++) {
if (i == 98) throw new Exception();
}
} catch (Exception e) {}
}
Stupid example, but I think you can see the point.
Rather than putting the condition in the loop, or
using the "break", and exception is thrown to stop
the loop.
I suppose what we could do to catch this, is look
for all Try blocks which *explicitely* throws the same
exception that is being caught. (If its thrown by
a method, thats OK.)
Thoughts?