File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes exception's 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 "exception Watch "exception New topic


nitin sharma
Ranch Hand

Joined: Feb 24, 2001
Posts: 290
public class fun
void func()
String str = "niitn";
if (str.length() == 0)
System.out.print(" Cow");
catch (Exception e) {
System.out.print(" and");
} finally
System.out.print(" Chicken");
System.out.println(" show");
public static void main(String[]args)
fun f=new fun();
In the above given code i expected an error at line number 13 because that line will never be reached.Please throw some light on it.
Junilu Lacar

Joined: Feb 26, 2001
Posts: 6529

The statement System.exit(0); has no special meaning to the Java compiler in terms of determining whether the succeeding statements are reachable or not. To the compiler the statement is just an invocation of a class method that can be
completed normally. Thus, the statement after it is reachable.
If you had a 'return' statement instead, then you'd get the unreachable error but you probably already know that.

Junilu - [How to Ask Questions] [How to Answer Questions]
I agree. Here's the link:
subject: exception's
It's not a secret anymore!