This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes about try and finally 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 "about try and finally" Watch "about try and finally" New topic
Author

about try and finally

Gnome986
Greenhorn

Joined: Jul 10, 2001
Posts: 11
code here:

here i use finally to catch the exception,but why compiler will occur error and tell me FileNotFoundException didn't be catch?
marilyn murphy
Ranch Hand

Joined: Aug 28, 2001
Posts: 84
>unreported exception java.io.FileNotFoundException; must be
>caught or declared to be thrown

>FileReader in = new FileReader( "no_exist_file" );

If you do not "catch" the exception, you must declare that you did not just *forget* to catch it. You must either "catch" or throw it. "finally" is not sufficient for that purpose.

Please re-register.
Muhammad Farooq
Ranch Hand

Joined: May 08, 2001
Posts: 356
Is it true that checked exception should either be declare as "throws" in the method header or catch specifically with that type of Exception(or with Exception as superclass of all exception)? Why finally is not sufficient enough to handle Exceptions?
--Farooq
[This message has been edited by Muhammad Farooq (edited August 28, 2001).]


Muhammad Farooq<br />Sun Certified Programmer for Java 2 Platform<br />Oracle8i Certified Professional Database Administrator
Johannes de Jong
tumbleweed
Bartender

Joined: Jan 27, 2001
Posts: 5089
Your user name (Gnome986) does not comply with the JavaRanch's naming policy. Pse change it if you wish to continue posting in our forums.
Thanks
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: about try and finally