directory-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Alex Karasulu" <akaras...@apache.org>
Subject Re: Constructors & Exceptions
Date Thu, 03 Jan 2008 20:40:48 GMT
Why is it bad to have a checked exception in the throws clause of a
constructor?

Isn't it better to be more explicit about the exception with the proper
exception type then wrap the exception or throw an unchecked exception that
complains about the same error?

Alex

On Jan 3, 2008 7:03 AM, Emmanuel Lecharny <elecharny@gmail.com> wrote:

> Hi guys,
>
> I'm facing an interesting question here : should constructors throw
> checked exceptions?
>
> I just feel like I don't like the idea at all, but may be I'm wrong...
>
> The problem is that for the new ServerEntry API, I have to guarantee
> that the constructors are called with valid parameters. There are many
> possible options :
> 1 -  use Assert in the constructors (but they will be disabled by
> default if you don't add the -ea in the JVM command line)
> 2 - use Checked Exception (but then the caller will have to try...catch
> the code
> 3 - use Runtime Exception
> 4 - don't do anything in the constructors, but handle the controls in
> setters
> 5 - just consider the user won't use the constructors with bad parameters
> 6 - default to a base object if inside the constructor, we have some
> exception
>
> This is not clear to me what should be the best solution. ATM, I incline
> to think that solution 3 is the less offending.
>
> wdyt ?
>
> --
> --
> cordialement, regards,
> Emmanuel L├ęcharny
> www.iktek.com
> directory.apache.org
>
>
>

Mime
View raw message