I know if java finds a line of code where it's guaranteed that control will never reach, then compiler reports unreachable code error.
consider following code.
static int method1() {
try{ return 1; }
catch(Exception e){ } // LINE-1
finally{ }
System.out.println("abc"); //LINE-2
return 2;
}
}
in above code
1 try block is guaranteed to exit by returning 1 but still lines after finally block (LINE-2 onwards) are reachable.
2. if i comment catch block (LINE-1), LINE-2 becomes unreachable.
Why is it so. Doesn't compiler able to see unconditional return in try block for case-1.