• 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:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Declaring a method that throwsThrowable

 
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello all,
can someone think of a reason as to why a method would be declared to throw a Throwable? i.e. why not just be restricted to Exception? After all, run-time exceptions don't have to be declared or caught?
Motivation: The finalize method of class Object.
thanks, Jamil
 
Author & Gold Digger
Posts: 7617
6
IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
As far as I know, I think that the finalize method is the only one declaring a Throwable in its throws clause. The reason is because the finalize method is usually invoked by the garbage collection thread to give a chance to an object to clean things up. Now, if for some reasons, the clean up should not be completed successfully (error or whatever), it shouldn't affect the rest of the program and that's why Any exception thrown by the finalize method causes the finalization of this object to be halted, but is otherwise ignored.
I think developers should never declare Throwables in their throws clause but restrict it to the exact common denominator exception that gets thrown from the method.
[ April 15, 2002: Message edited by: Valentin Crettaz ]
 
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
They don't have to be.. but you can
 
J Hreich
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks Val
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic