Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

about try and finally

 
Gnome986
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 84
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
>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
Posts: 356
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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).]
 
Johannes de Jong
tumbleweed
Bartender
Posts: 5089
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic