T
Tom St Denis
As someone pointed out exceptions in Java are really just goto,
[...]
One significant difference is that `goto' specifies the
target of the control transfer. Upon seeing `goto label' you
can hunt for `label' and know where execution will resume. But
when you see `throw new HissyFit()' all you know is that you're
going somewhere else. Where? Well, um, "it depends."
Another difference is that with `goto label', when control
arrives at `label' there's no additional information. "How did
I get here?" is unknown, unless the program is amenable to a
static analysis that reveals there's only one point of departure.
An exception carries a lot of information about its circumstances,
and that information is available to -- and manipulable by -- the
code at the `catch' point.
It seems to me that "someone" has oversimplified.
Usually I have code like
if ((err = blah()) != OK) goto ERROR;
So you can return "err" to the user. The only real downside is you
wouldn't know WHICH function call returned that error code. Which is
where I get more clever. In my code on GLIBC platforms when an error
occurs inside a deeper function I get a stacktrace and log it. Then
when the user dumps the error log they get a stack trace of every
error.
Most of the time that alone is sufficient to figure out the problem
without even firing up a debugger.
Tom