>"We could add useful methods to DuplicateUsernameException,..."
It would be useful to add some contructors.
The article failed to describe wrapped (or nested) exceptions: http://www.javaworld.com/javaworld/javatips/jw-javatip91-p3.html
>"Checked exceptions are also accused of breaking encapsulation. Consider the following:
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: http://www.javaworld.com/javaworld/jw-10-2003/jw-1003-generics.html?
"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):