Exceptions (Was RE: [ANN] Cleaned up KomHttpServer on SM)

goran.krampe at bluefish.se goran.krampe at bluefish.se
Fri Nov 5 06:51:56 UTC 2004


Hi!

"Russell Penney" <russell.penney at tincanct.com> wrote:
> Goran,
>    Thanks for the comments. If you do have to handle an Exceptions down in
> the bowels of your code, is it better to perhaps handle the Exception and
> then signal a more general Exception so that code further up can still
> detect something has gone wrong?

Yes, definitely - that is how you *should* do it. For example, network
code may catch several different networking exceptions and then resignal
them all in some general form so that the outer levels can handle it in
a more simplified way. It is all about keeping knowledge local. IMHO of
course - this is probably an area of many views. :)

But since I haven't looked into the reasons for the code in question I
really don't know why it swallows.

A sidenote of interest: In Java you have the forced
"throws/try/catch"-hysteria causing less experienced developers to
sprinkle their code with more or less empty try-catches. That is very,
very bad. Since Java forces you to either handle exceptions thrown by
the lower layers OR declare that you also will throw them (unlike
Smalltalk) this has the effect on developers that they, at least early
on in development, tend to write empty catch-code because they "just
want the damn code to compile and run".

And then, just like with class comments (cough, cough), they never get
the time to go back and fix those empty catches - until someone spends
13 hours trying to track down a bug and eventually finds out that the
reason for the bug being so DAMN hard to track down is because some dork
has swallowed an exception with an empty catch. :)

Well, end of rant. Anyone wishing to defend Java in this case can of
course make the argument that the rules are good and fosters good
exception handling etc etc - and to some extent they would be right. But
I have seen the above scenario too often to really think the positives
outweigh the negatives.

regards, Göran

PS. It would be a GREAT thing if someone wrote a good Exception-howto
for us Squeakers. There are some docs on the subject out there to read,
I vaguely remember a Word document..., but in short it would be nice if
someone with the knowledge could put down some guidelines for the rest
of us to follow. IMHO. :)



More information about the Squeak-dev mailing list