Re: How to handle exceptions in constructor?



On Mon, 27 Jun 2005 03:18:40 +0000, George George via JavaKB.com 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

--
You can't run away forever,
But there's nothing wrong with getting a good head start.
--- Jim Steinman, "Rock and Roll Dreams Come Through"


.



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?
    ... 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)
  • exception inside constructors and finalize
    ... 1.how can we handle exception inside constructors and finalize method? ... 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)