my dog learned polymorphism
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes problem in throwing exceptions ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "problem in throwing exceptions ?" Watch "problem in throwing exceptions ?" New topic

problem in throwing exceptions ?

yamini nadella
Ranch Hand

Joined: Apr 13, 2004
Posts: 257
(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") %>
<% throw new ArithmeticException("error"); %>
given HTTP Status 500 error. why this difference between JSP Expression and scriptlets
<%= 9/0 %>
gave message as java.lang.ArithmeticException: / by zero
but in case of scriptlets <%out.print(""+9/0); %>
caused HTTP status 500.
<%= new ArithmeticException("error") %>
<%= 9/0 %>
ram raja rani

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


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

here i am trying to use JSTL core

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


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

Adrian Pang
Ranch Hand

Joined: Feb 20, 2004
Posts: 40
<%= 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")%>

SCJP 1.4, SCWCD 1.4, SCBCD 1.3
I agree. Here's the link:
subject: problem in throwing exceptions ?
It's not a secret anymore!