• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

problem in throwing exceptions ?

 
yamini nadella
Ranch Hand
Posts: 257
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
(1) Inside JSP if exception comes then what happens? does it throw exception?
(2) when I thrown exception in expressions then it only shown the exception name which I thrown and continued execution of rest .
<%= new ArithmeticException("error") %>
(3)
<% throw new ArithmeticException("error"); %>
given HTTP Status 500 error. why this difference between JSP Expression and scriptlets
(4)
<%= 9/0 %>
gave message as java.lang.ArithmeticException: / by zero
but in case of scriptlets <%out.print(""+9/0); %>
caused HTTP status 500.
(5)
<%= new ArithmeticException("error") %>
<%= 9/0 %>
</c:catch>
ram raja rani

(6)
<%= new ArithmeticException("error") %>
<%= 9/0 %>

INSIDE SCRIPT

above part of script gave output as

java.lang.ArithmeticException: error INSIDE SCRIPT java.lang.ArithmeticException: / by zero

why it did not give error message as

java.lang.ArithmeticException: error
java.lang.ArithmeticException: / by zero INSIDE SCRIPT

(7)
here i am trying to use JSTL core

<c:catch var="variableException">
<%= new ArithmeticException("error") %>
</c:catch>

${variableException}

in this script I thought exception is caught and stored in variable variableException. but catch did nothing.

Regards,
Yamini.
 
Adrian Pang
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
<%= new ArithmeticException("error") %>

does not throw the ArithmeticException. You just created a new object of class ArithmeticException, and printed this object. The code will be similar to:

out.println(new ArithmeticException("error"));

To throw an exception, you must use a scriplet <% throw new ArithmeticException("error")%>
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic