Re: exception inside constructors and finalize



"sarath" <mesarath@xxxxxxxxx> writes:

> 1.how can we handle exception inside constructors and finalize method?

try/catch or (for constructors) throws clause - as usual.

> 2.what will happen when an exception occur inside constructors and
> finalize()?

Same as happens when it occurs anywhere else: You need to pass it on
or catch it. Since finalize() is inherited from Object, you cannot add
any exception throws in it.

> will it be properly garbage collected ?

What do you mean? An exception object- like any other, will be a
candidate for collection as soon as it's no longer used.

> 3.can we call finalize method explicitly ? and what will happen then ?

It's a method, so you can call it yourself. What will happen is that
the code will be executed. Since you are calling it outside it's
normal lifecycle use, you might screw up your program doing so, if it
releases any resources or things like that.
.



Relevant Pages

  • Re: exception inside constructors and finalize
    ... >> 1.how can we handle exception inside constructors and finalize method? ... > try/catch or (for constructors) throws clause - as usual. ...
    (comp.lang.java.help)
  • Re: throw exception in the finalize
    ... I dont know your requirement clearly but based on the fact of finalizer..you ... > if i throw exception there it is not seen on the page. ... > is there a way to throw exception on the finalize method in order to check ...
    (microsoft.public.dotnet.framework.aspnet)
  • 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)
  • 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)