Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

after sendRedirrect why compiler is not giving unreachable code exception  RSS feed

 
naveen shrimal
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Rob Spoor
Sheriff
Posts: 20893
81
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65830
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just to re-emphasisze: your assertion that code following a redirect will not execute is false.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!