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

Compiler :  RSS feed

 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The following code when compiled gives an error that FileNotFoundException is never thrown in the body of the try statement. Understandably so cause we do not have any call to a method that throws this exception. (It would work even if we change the FileNotFound to Throwable in line 1)


But if were to change the code to

It compiles fine and gives an output. Why does it not give a similar message here - no exception is thrown in the try etc...?
Thanks for the help.
Deepti
 
Ranch Hand
Posts: 203
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Checked Exceptions Vs Runtime Exception
 
Ranch Hand
Posts: 417
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
marathe:
if we replace RuntimeException in the catch clause the compile goes through fine. But why does compile go fine for Throwable and Exception as well.
Because compile fails for any other exceptions other than error, Throwable and Exception. why ?
For Errors and its subclasses it is understood but what about Throwable and Exception ??
 
Ranch Hand
Posts: 281
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I believe it's because a RunTimeException can always be thrown(wihtout declaring it in a throws statement) and since RunTimeException is a subclass of Exception (and thus also Throwable), it's ok if you set up a catch trying to catch Exception or Throwable since a RunTimeException is an Exception.
If I'm wrong someone please correct me.
[ February 01, 2002: Message edited by: Rick Reumann ]
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!