Win a copy of Practical SVG this week in the HTML/CSS/JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

after sendRedirrect why compiler is not giving unreachable code exception

 
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: 20822
68
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: 65537
108
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.
 
Are you okay? You look a little big. Maybe this tiny ad will help:
the new thread boost feature brings a LOT of attention to your favorite threads
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!