Best Practices for Exception Handling
Subject:   Worst Practices
Date:   2003-11-20 11:53:11
From:   anonymous2

>"We could add useful methods to DuplicateUsernameException,..."

It would be useful to add some contructors.
The article failed to describe wrapped (or nested) exceptions:

>"Checked exceptions are also accused of breaking encapsulation. Consider the following:
List getAllAccounts()throwsFileNotFoundException"

Checked exceptions do not break encapsulation. Converting the low level FileNotFoundException into another checked exception demonstrates this.

>"If the client cannot do anything useful, then make the exception unchecked. "

The trouble is that you do NOT know if clients
can(not) do anything useful. It is better to give clients the option.

"In this example, the finally closes the connection and throws a RuntimeException if there is problem with closing the connection."

Dangerous. Throwing Exceptions from a the finally block may result in losing the original exception.

Throwing generic Excpetions(& RuntimeExceptions) is often a bad idea:

"In an EJB throwing a system exception (RemoteException, RuntimeException or Error) does discard the EJB instance "

I agree.This article was directed at newbies.Here is someting better for newbies:

Here is a better article of Best Practices:

"It took the C++ community several years to decide on how to use exceptions. This debate has just started in the Java community."

I have not seen any debate- Just MUD (MS FUD):

1 to 1 of 1
  1. Worst Practices
    2003-11-20 12:19:26  anonymous2 [View]

1 to 1 of 1