directory-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Emmanuel Lecharny <>
Subject Constructors & Exceptions
Date Thu, 03 Jan 2008 12:03:42 GMT
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 
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 

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

View raw message