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?
I'm facing an interesting question here : should constructors throw
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
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.