• 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

confused on checked exceptions

 
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hello folks,

only case 1 will result in compile Error: "exception java.io.IOException is never thrown in body of corresponding try statement"
i am confused with the outcome: is the error above occurs only on checked exception? if so, how come both case 4,5 compiles successfully? because Exception and Throwable are supposed to be checked exception? or not?
 
author
Posts: 3252
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It's because both Exception and Throwable have unchecked exceptions as subclasses. So where you sayWhen the compiler tries to figure out whether your catch clause can ever be executed, it comes up with the answer "yes" because it assumes that an unchecked RuntimeException can always be thrown, anywhere. And a RuntimeException or subclass would be caught by your Exception catch clause.
Same story for Throwable, except that that will catch Error as well.
- Peter
 
reply
    Bookmark Topic Watch Topic
  • New Topic