Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Unreachable statements

 
Veena Pointi
Ranch Hand
Posts: 442
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

The above code compiles & runs fine.
Shouldn't th above code give complier error that "Unreachable statement"?Co line 1 is never reached What are the scenarios when compiler throws unreachable statement error?Are these kind of questions ,where compiler gives error that"Unreachable statement" going to appear in the exam?
thanks
Veena
 
Vad Fogel
Ranch Hand
Posts: 504
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Method m1() might throw an exception that would halt the program as opposed to having a straight statement like throw new Exception(); A call to a method throwing an exception shouldn't make a statement immediately after it unreachable. Don't forget, m1() can be overridden not to throw any exception.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic