This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes unreachable try{ Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "unreachable try{" Watch "unreachable try{" New topic
Author

unreachable try{

Ankur kothari
Ranch Hand

Joined: Sep 06, 2009
Posts: 531


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

Joined: Oct 22, 2009
Posts: 11
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

Joined: Sep 06, 2009
Posts: 531
i know that....but what is there to give an error in this?
Linda Wiklund
Greenhorn

Joined: Oct 22, 2009
Posts: 11
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

Joined: Sep 06, 2009
Posts: 531
Thanks I will keep that in my mind as long as possible......
 
 
subject: unreachable try{
 
Similar Threads
Hierarchy in Exceptions
exceptions
Dan's Exception Handling question
exception
Exception handling ques