aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Compiler : Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Compiler : " Watch "Compiler : " New topic
Author

Compiler :

Deepti Dixit
Greenhorn

Joined: Dec 27, 2001
Posts: 17
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
Shivaji Marathe
Ranch Hand

Joined: Jan 11, 2002
Posts: 203
Checked Exceptions Vs Runtime Exception
mark stone
Ranch Hand

Joined: Dec 18, 2001
Posts: 417
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 ??
Rick Reumann
Ranch Hand

Joined: Apr 03, 2001
Posts: 281
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 ]
 
jQuery in Action, 2nd edition
 
subject: Compiler :