• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Unreachable Statements

 
Joe Harry
Ranch Hand
Posts: 10081
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Guys,

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.
 
Aniket Patil
Ranch Hand
Posts: 218
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Read JLS 3.0, 14.21
[ December 21, 2006: Message edited by: Aniket Patil ]
 
Ajith George
Ranch Hand
Posts: 109
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For example, if you are writing any statement after a return statement in a method, this could happen.
 
Ashwin Kumar
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic