How to handle exceptions in constructor?



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. But I am not quite sure whether I am correct
since I have not seen any constructors which throw exceptions before.

Could anyone help?


Thanks in advance,
George


--
Message posted via JavaKB.com
http://www.javakb.com/Uwe/Forums.aspx/java-setup/200506/1
.



Relevant Pages

  • Re: How to handle exceptions in constructor?
    ... George via JavaKB.com wrote: ... should we throw the exception to the invoker of the constructor or simply catch the exception? ...
    (comp.lang.java.help)
  • Using the UnhandlerExceptionEventHandler in a control hosted by IE
    ... I want to handle the 'UnhandledException' in my application, ... constructor, ... I'm forcing a 'Division by zero' exception to test it, ... Prev by Date: ...
    (microsoft.public.dotnet.framework.windowsforms.controls)
  • Re: How to handle exceptions in constructor?
    ... Stefan Schulz wrote: ... >> 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 ... >> since I have not seen any constructors which throw exceptions before. ...
    (comp.lang.java.help)
  • Re: How to handle exceptions in constructor?
    ... > instance of the object has not been created successfully, so that the invoker ... > since I have not seen any constructors which throw exceptions before. ... You absolutely should pass the exception through, ... Prev by Date: ...
    (comp.lang.java.help)
  • Re: Exception in a constructor
    ... > If an exception occurs or is thrown in my constructor, ... Prev by Date: ...
    (microsoft.public.dotnet.languages.csharp)