It's not a secret anymore!
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Unreachable Statements Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Unreachable Statements" Watch "Unreachable Statements" New topic

Unreachable Statements

Joe Harry
Ranch Hand

Joined: Sep 26, 2006
Posts: 10031


I have come across that in some conditions, if we have an unreachable statement, it gives us a compiler error. Under what circumstances will this happen. Any references to any websites, anyone knows??

Thanks in advance.

SCJP 1.4, SCWCD 1.4 - Hints for you, Certified Scrum Master
Did a rm -R / to find out that I lost my entire Linux installation!
Aniket Patil
Ranch Hand

Joined: May 02, 2006
Posts: 218
Read JLS 3.0, 14.21
[ December 21, 2006: Message edited by: Aniket Patil ]

SCJP 5.0 | SCWCD 1.4 <br /> <br />If you don't know where you are going, any road will take you there!
Ajith George
Ranch Hand

Joined: Dec 22, 2005
Posts: 109
For example, if you are writing any statement after a return statement in a method, this could happen.

SCJP 1.4, Brainbench
LinkedIn - Blog
Ashwin Kumar

Joined: Oct 13, 2005
Posts: 27
Another example would be:
try {
throw new RuntimeException();
catch(Exception e) { }
catch(RuntimeException re) { }

Here the second catch would give you a 'catch not reached' error
as Exception would catch all exceptions on the universe!!

SCJP 1.4<br />SCBCD 5.0<br />SCWCD 1.4 (Preparing)
I agree. Here's the link:
subject: Unreachable Statements
jQuery in Action, 3rd edition