• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

How to find unreachable stmt?

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
There are a lot of cases of compile error because of UNREACHABLE statements. some examples:
<QUOTE>
int i=0;
for(;;++i){
System.out.println("Hai");
}
system.out.println("after");

OR
if (false) System.out.println("unreachable");

OR
after try-catch-finally with return stmts
</QUOTE>
Could any body explain the conception of discovering those unreachable?
thanx
 
Ranch Hand
Posts: 371
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you can think of the examples, you already know what kind of logic will produce unreachable statements.
 
Ranch Hand
Posts: 418
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
To discover an unreachable stmt, always remember following points...
1. return should be the last stmt in any 'block'.
ie.{
...
{
...
return;
//some stmt here is unreachable.
}
//however here stmts are allowed.
return;
}
2. If u return something from finally then u can't write anything after finally.
for eg.
void meth()throws IOException
{
try
{
System.out.println("try");
throw new IOException();
}
catch(IOException e)
{
System.out.println("catch");
}
finally
{
System.out.println("finally");
return;
}
System.out.println("after finally"); //error!!!
}

3. if (false)
System.out.println("reachable");//allowed
But following is an error,...
for( int i=0;false ;i++)
System.out.println("unreachable");//error

however
for (int i=0; ;i++) System.out.println("reachable");//allowed
is allowed.
4. similarly,
while(false)
System.out.println("unreachable");//not allowed
Hope this helps. Can anybody add some other unreachable conditions ???
Rashmi

[This message has been edited by Rashmi Gunjotikar (edited August 31, 2001).]
 
Normally trees don't drive trucks. Does this tiny ad have a license?
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic