Re: How to handle exceptions in constructor?



Thanks Stefan,


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
>> 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?
>
>You absolutely should pass the exception through, or at least throw
>another, if your object could not be successfully constructed. A
>constructor can throw Exceptions just like any other method
>

Your reply is very helpful.


regards,
George


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



Relevant Pages

  • How to handle exceptions in constructor?
    ... When exceptions occur in constructor so that the instance of the object can ... should we throw the exception to the invoker of the ... the invoker can not see whether the instance of the object has ... Prev by Date: ...
    (comp.lang.java.help)
  • 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)
  • 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: type checking
    ... >it's not far from your favourite SWIG-supported language. ... when its constructor raised an exception. ... It hasn't really been an issue so far, but I guess C# constructors ... This is one issue I already have with Java/C# style garbage collection ...
    (comp.lang.python)
  • Re: Exception unwinding base destructor called - why?
    ... > We are creating an instance of Derived inside an exception handler. ... > mechanism is calling the destructor for the base class. ... > Where is the logic in partially deconstructing an aggregate object that's ... > operations in my constructors (although I have not at this point worked ...
    (comp.lang.cpp)