Re: How to handle exceptions in constructor?
- From: Thomas Fritsch <i.dont.like.spam@xxxxxxxxxxx>
- Date: Mon, 27 Jun 2005 13:11:06 +0200
George via JavaKB.com wrote:
I think so, too.Hello everyone,
When exceptions occur in constructor so that the instance of the object can not be created, should we throw the exception to the invoker of the constructor or simply catch the exception (and not throw it again)?
I think we should not catch the exception (and not throw it again), since in this approach, the invoker can not see whether the instance of the object has been created successfully.
I think we should throw the exception to let the invoker know that the instance of the object has not been created successfully, so that the invoker can peform appropriate actions.
There are many, for example the constructors of java.io.FileInputStream, java.net.URL or java.rmi.server.UnicastObject .... But I am not quite sure whether I am correct since I have not seen any constructors which throw exceptions before.
Could anyone help?
--
"Thomas:Fritsch$ops:de".replace(':','.').replace('$','@').
- Follow-Ups:
- Re: How to handle exceptions in constructor?
- From: George George via JavaKB.com
- Re: How to handle exceptions in constructor?
- References:
- How to handle exceptions in constructor?
- From: George George via JavaKB.com
- How to handle exceptions in constructor?
- Prev by Date: formatting floats in a table
- Next by Date: Re: formatting floats in a table
- Previous by thread: How to handle exceptions in constructor?
- Next by thread: Re: How to handle exceptions in constructor?
- Index(es):
Relevant Pages
|