Unreachable statement when using return in finally?
- by abson
this compiles
class ex1
{
public int show()
{
try
{
int a=10/10;
return 10;
}
catch(ArithmeticException e)
{
System.out.println(e);
}
finally
{
System.out.println("Finally");
}
System.out.println("hello");
return 20;
}
}
on the other hand this doesn't
class ex15
{
public int show()
{
try
{
int a=10/0;
return 10;
}
catch(ArithmeticException e)
{
System.out.println(e);
}
finally
{
System.out.println("Finally");
return 40;
}
System.out.println("hello");
return 20;
}
}
and gives unreachable statement System.out.println("hello"); error. why is it so?