Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

finalize and finalizer : Need clarification

 
Mathew Kuruvilla
Ranch Hand
Posts: 145
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A finalize method may throw exceptions and not finish.
However any exception thrown but not caught by a finalizer when invoked by the garbage collector is ignored.
Which of the above is true?
 
David Weitzman
Ranch Hand
Posts: 1365
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It sounds to me like they say the same thing. What conflict do you see?
 
Mathew Kuruvilla
Ranch Hand
Posts: 145
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A finalize method may throw exceptions and not finish.
=> In other words, if the garbage collector calls the finalize method for an object and the call results in an exception and this exception is not caught, the method returns from that point back to the garbage collector.
However any exception thrown but not caught by a finalizer when invoked by the garbage collector is ignored.
=>In other words, if the garbage collector calls the finalizer for an object and the call results in an exception and this exception is not caught, the exception is ignored and the method continues till it is completed.
???
 
Jose Botella
Ranch Hand
Posts: 2120
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
From the API for finalize() in Object:
"
If an uncaught exception is thrown by the finalize method, the exception is ignored and finalization of that object terminates.
"
The finalize method is halted. The exception is ignored in the sense that is doesn't goes up in the call stack, and it is not printed in the output. However the object is garbage collected.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic