This week's book giveaway is in the OCAJP forum.
We're giving away four copies of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) and have Khalid A Mughal & Rolf W Rasmussen on-line!
See this thread for details.
Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

explain try catch problem

 
vineet walia
Ranch Hand
Posts: 138
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


can any body explain why this is giving error
this question is from exam lab ?
 
Nitish Bangera
Ranch Hand
Posts: 537
Eclipse IDE Java Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yeah because exception1 and exception2 are both checked exceptions and when you are catching a checked exception, there should be a statement in the try block which throws or declares that it throws that checked exception. I guess the explanation given by examlab is pretty much clears that point.
 
Jaydeep Mazumdar
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think the error message is pretty self explainatory:

Exception in thread "main" java.lang.Error: Unresolved compilation problem:
Unreachable catch block for exception1. This exception is never thrown from the try statement body
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic