posted 23 years ago
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).]