This week's book giveaway is in the Artificial Intelligence forum.
We're giving away four copies of Pragmatic AI and have Noah Gift on-line!
See this thread for details.
Win a copy of Pragmatic AI this week in the Artificial Intelligence forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
Bartenders:
  • Carey Brown
  • Tim Holloway
  • Joe Ess

Throwable  RSS feed

 
Ranch Hand
Posts: 113
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Compiles and runs fine.
If the catch clause @ Line 1 is replaced with any of Throwable's subclasses, predictably, a compiler error along the lines of 'This type of Exception is never thrown in the body of the try statement'...
What's the reasoning behind the 'Throwable' in the catch clause working...
 
Ranch Hand
Posts: 1873
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi V Bose,
Thats because Throwable includes Runtime and Checked exceptions both. If you look at API it will tell that,
Throwable is parent of Exception,Error and in Error API it says,

A method is not required to declare in its throws clause any subclasses of Error that might be thrown during the execution of the method but not caught, since these errors are abnormal conditions that should never occur.

which means the code in try catch can throw Error even w/o making methods called in that block as "throws Error" you know.
So, when we write catch Throwable it assumes that we want to probably catch some Error which occurs at runtime. If you write Exception then it means it could be checked exception and in that case it goes and see if there is a possibility of getting any checked exception in the code or not. Hence it doesn't compile if there is no possbility of getting checked exception in the try catch block.
Hope it helps.
Maulin
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!