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

unreachable try{

 
Ankur kothari
Ranch Hand
Posts: 531
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


compile error: unreachable statement try{

but why do i get this?
if there was not a throw statement just after the try block then isnt case 2 and case 3 unreachable statement as they are never reach as x is 1
 
Linda Wiklund
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
on line 10 you throw an exception, hence, JVM will exit the method. the try-statement on line 11 will NEVER be reached.
 
Ankur kothari
Ranch Hand
Posts: 531
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i know that....but what is there to give an error in this?
 
Linda Wiklund
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Code that never will be reached, never used is redundant. It should not bee there. You'll get the same error if you have code after a return statement.
 
Ankur kothari
Ranch Hand
Posts: 531
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks I will keep that in my mind as long as possible......
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic