• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

exception's

 
nitin sharma
Ranch Hand
Posts: 290
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 7750
61
Android Eclipse IDE IntelliJ IDE Java Linux Mac Scala Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic