• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

finalize method

 
Ranch Hand
Posts: 270
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
Since the signature of finalize() is..
protected void finalize() throws Throwable {}
I guess finalize can throw ANY exception (checked/unchecked)
How are these exceptions dealt with? I mean where are checked expections caught?
Thanks.
 
Ranch Hand
Posts: 504
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
JLS, Chapter 12.6:


If an uncaught exception is thrown during the finalization, the
exception is ignored and finalization of that object terminates.

 
Cathy Song
Ranch Hand
Posts: 270
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Vad.
Does the "finalization of that object terminates" normally or it is prematurely terminated as soon as exception occurs?
 
Vad Fogel
Ranch Hand
Posts: 504
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Cathy Song:
Thanks Vad.
Does the "finalization of that object terminates" normally or it is prematurely terminated as soon as exception occurs?


I believe it terminates prematurely without completing the specified finalize() tasks. Take a look at this code:

An exception gets thrown, but then it gets supressed (peculiar behaviour of finalize()).
 
reply
    Bookmark Topic Watch Topic
  • New Topic