directory-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Felix Knecht <>
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

Best Practices for Designing the API

Having said all of this, let us now talk about how to design an API that throws exceptions
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  |

Anyway I'm still +1 for IllegalArgumentException

View raw message