after sendRedirrect why compiler is not giving unreachable code exception
posted 5 years ago
Suppose I do have code of 10 lines among then on second line I transfer the control on new resource (html,servlet,jsp any) than lines from 3 to 10 wont never get their canse to execute so why I am not getting Exception of Unreachable code here.
Because the method doesn't cause the rest of the method to not be executed. There are only two things that can do that (a return statement and exceptions). The rest is still executed, it's just not included in the output.
However, even if the method stopped the rest of the method from being executed, the compiler doesn't know that. It's a bit limited. For example, the following is also legal even though the return statement will never be executed:
You know the return false line will never be reached, I know it, but the compiler doesn't.