• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

about try and finally

 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Ranch Hand
Posts: 85
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 356
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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).]
 
tumbleweed
Posts: 5089
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic