It's not a secret anymore!*
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


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "exception Watch "exception New topic
Author

exception's

nitin sharma
Ranch Hand

Joined: Feb 24, 2001
Posts: 290
public class fun
{
void func()
{
String str = "niitn";
try
{
if (str.length() == 0)
{
System.out.print("The");
}
System.exit(0);
System.out.print(" Cow");
}
catch (Exception e) {
System.out.print(" and");
System.exit(0);
} finally
{
System.out.print(" Chicken");
}
System.out.println(" show");
}
public static void main(String[]args)
{
fun f=new fun();
f.func();
}
}
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
Bartender

Joined: Feb 26, 2001
Posts: 4442
    
    5

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.
J.Lacar

Junilu - [How to Ask Questions] [How to Answer Questions]
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: exception's
 
Similar Threads
Exception question.
exception handling
Multi Dimensional Arrays and nextBoolean
code unreachable exception
Please Help