• 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

Prob in Exception

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


If I remove the comments from line one then it gives compile time Exception "java.lang.InterruptedException was never thrown.
while keeping the comments on line 1 compiles fine.I dont understand the logic.
I got similar logic code in Devka's Examlab mock.
I scored 37% in the diagnostic exam and 52 % in master Exam really worrid I have my exam on monday.
please help

 
Bartender
Posts: 4568
9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
InterruptedException is a checked exception. So any method that can throw it has to declare it. This means that the compiler can tell that your code within the try block cannot possibly throw an InterruptedException. Therefore trying to catch one must be an error, so the compiler helpfully tells you this.

But Exception is the super-type for all the RuntimeExceptions that don't have to be declared. So as far as the compiler is concerned, the code could possibly throw an Exception. So trying to catch one is fine.
 
Shashank Sharma
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks
 
The moustache of a titan! The ad of a flea:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic