This is regarding unreachable code w.r.t to the return statement :
public int checkReturn()
{
int x = 0 ;
try {
System.out.println(" TRY ");
int y = x/0;
return x;
}
catch( Exception e )
{
System.out.println(" CATCH ");
return x;
}
finally
{
System.out.println(" FINALLY ");
return x;
}
// return x;
}
Point 1 :
With reference to try-catch-finally, i can have return in each
block. But i cannot un-comment the last line as finally block in
any case will be executed and so the last line becomes unreachable.
Point 2 :
We can remove the comment from the last line,but we need to comment return x of finally block.
So if the finally block is containing return, then
we don't need to declare a return after it or at the end ?
What other case of some statement becoming unreachable are
possible with reference to try-catch-finally ?
public int checkReturn()
{
int x = 0 ;
try {
System.out.println(" TRY ");
int y = x/0;
return x;
}
catch( Exception e )
{
System.out.println(" CATCH ");
return x;
}
finally
{
System.out.println(" FINALLY ");
return x;
}
// return x;
}
Point 1 :
With reference to try-catch-finally, i can have return in each
block. But i cannot un-comment the last line as finally block in
any case will be executed and so the last line becomes unreachable.
Point 2 :
We can remove the comment from the last line,but we need to comment return x of finally block.
So if the finally block is containing return, then
we don't need to declare a return after it or at the end ?
What other case of some statement becoming unreachable are
possible with reference to try-catch-finally ?