Two Laptop Bag
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
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "about try and finally" Watch "about try and finally" New topic

about try and finally


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; 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?
[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

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.
I agree. Here's the link:
subject: about try and finally
It's not a secret anymore!