[733] in java-interest

home help back first fref pref prev next nref lref last post

Catch-all Exception handlers

daemon@ATHENA.MIT.EDU (Mick Jordan)
Mon Jul 17 19:50:56 1995

Date: Mon, 17 Jul 1995 14:59:45 -0700
From: Mick.Jordan@Eng.Sun.COM (Mick Jordan)
To: java-interest@java.Eng.Sun.COM

Browsing this mailing list I have come across several places where the
following idiom is used/recommended [the latest in the new Java Language 
Environment white paper]:

try {
  // some code
} catch (Exception e) {
  // something went wrong
}

While there is a place for this kind of catch-all, it's bad programming
practice in general because it can mask real programming errors. Much
better for each abstraction to define and document the exceptions it
can raise (preferably converting implementation-dependent exceptions
into abstraction-specific exceptions).

Unfortunately, unless exceptions are part of the method signature, there
is no way to check that an exception is handled, which tends to lead to the
kind of defensive programming above.

Mick Jordan

-
Note to Sun employees: this is an EXTERNAL mailing list!
Info: send 'help' to java-interest-request@java.sun.com

home help back first fref pref prev next nref lref last post