• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Exception in jsp

 
nisha chidella
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
can we explicitly throw an exception in jsp ? i guess we would never need to throw an exception from a jsp. or is there any case in which we would have to ? .

sorry if it's a totally dumb question.
 
Ankit Garg
Sheriff
Posts: 9577
33
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nisha you would have to use a scriptlet to throw an exception in a JSP page. I don't think there is any other way. I am not a pro at JSP expression language so I don't know if we can do that with using an illegal calculation like dividing a number by 0 etc...
 
nisha chidella
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
we always get a unreachable compiler error when we explicilty throw an exception from a scriptlet like if we did this:

<% throw new ServletException() %>

even if its the last line of the scriptlet. because in the generated servlet, many more lines are added after this line. so does it mean we can never explicitly throw an Exception using throw?
 
Vijitha Kumara
Bartender
Pie
Posts: 3930
21
Chrome Fedora Hibernate
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ankit Garg wrote:I don't know if we can do that with using an illegal calculation like dividing a number by 0 etc...


Yes, That's possible it'll throw an exception.
 
nisha chidella
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, That's possible it'll throw an exception.


that way we can. we can easily even get the nullPointerException but what i want to know is that can we explicitly throw an exception using throw? If yes, how ? and whether there would be a need to do this in any scenario ?
 
Vijitha Kumara
Bartender
Pie
Posts: 3930
21
Chrome Fedora Hibernate
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
but what i want to know is that can we explicitly throw an exception using throw? If yes, how ?


We can't do it like you are saying since whenever you put it in a scriptlet that will ended up inside the service method which the container construct all the lines container adds below that would be unreachable. But we should be able to do it within a JSP declaration. It should be OK (though I havent' tried that )
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic