directory-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Felix Knecht <fel...@apache.org>
Subject Re: Constructors & Exceptions
Date Thu, 03 Jan 2008 22:15:30 GMT
Emmanuel Lecharny schrieb:
> Alex Karasulu wrote:
>> Why is it bad to have a checked exception in the throws clause of a
>> constructor?

Another approach could be (from http://www.onjava.com/pub/a/onjava/2003/11/19/exceptions.html):

Best Practices for Designing the API

Having said all of this, let us now talk about how to design an API that throws exceptions
properly.
1. When deciding on checked exceptions vs. unchecked exceptions, ask yourself, "What action
can the client code take
when the exception occurs?"

If the client can take some alternate action to recover from the exception, make it a checked
exception. If the client
cannot do anything useful, then make the exception unchecked. By useful, I mean taking steps
to recover from the
exception and not just logging the exception. To summarize:

Client's reaction when exception happens | Exception type
-----------------------------------------+-------------------------------
Client code cannot do anything           | Make it an unchecked exception
                                         +
Client code will take some useful        | Make it a checked exception
recovery action based on information in  |
exception


Anyway I'm still +1 for IllegalArgumentException
Felix

Mime
View raw message