File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes Exception: c:catch doubt 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 "Exception: c:catch doubt" Watch "Exception: c:catch doubt" New topic
Author

Exception: c:catch doubt

Chandra Bhatt
Ranch Hand

Joined: Feb 28, 2007
Posts: 1707
Hi,

Please see what I am trying to do:

In DD:




In errorPage.jsp


In badPage.jsp:



I was assuming the output as :
Inside the catch
There was an exception java.lang.NullPointerException
Output of errorPage.jsp because of exception caused in line #1

But the output is only containing the output from errorPage.jsp as
divide by zero comes. When I remove the code that caused divide by zero
then only the NPE comes. I see the divide by zero exception supersedes the
NPE.
One more thing: Even if I don't write <%@page errorPage ="errorPage.jsp"%>
in the badPage.jsp, it works for divide by zero exception.

I am using apache-tomcat-5.5.23

Please HELP!

Thanks,

[ June 02, 2007: Message edited by: Chandra Bhatt ]

[ June 02, 2007: Message edited by: Chandra Bhatt ]
[ June 02, 2007: Message edited by: Chandra Bhatt ]

cmbhatt
Niranjan Deshpande
Ranch Hand

Joined: Oct 16, 2005
Posts: 1277
<error-page>
<exception-type>java.lang.ArithmeticException</exception-type>
<location>/errorPage.jsp</location>
</error-page>

see the exception type highlighted above..since you are using a ArithmeticException, the errorPage.jsp will be invoked each time a a arithmatic exception ( divide by zero ...in your case) is thrown..

thats why..you are not getting the error page for the null pointer exception..

try using a java.lang.Exception as the exception type...then your errorPage will be a catch all error page

hth


SCJP 1.4 - 95% [ My Story ] - SCWCD 1.4 - 91% [ My Story ]
Performance is a compulsion, not a option, if my existence is to be justified.
Chandra Bhatt
Ranch Hand

Joined: Feb 28, 2007
Posts: 1707
Thanks Niranjan,


Still I am not getting why the previous exception message is not
shown on my web page. As in above case, I am only getting the last exception
caused as divide by zero and the exception I caught inside the catch is lost.
I also tried to define the error page for NPE in DD.

Please put some light on this!


Thanks,
Chandra Bhatt
Ranch Hand

Joined: Feb 28, 2007
Posts: 1707
Got It,

Actually the idea didn't come in my head, that the errorPage will be called
dynamically in case exception occurs, so the previous page content will be
superseded by the further page that is called when next exception is
generated.


Note: I didn't write the <%@ page isErrorPage="true"%> on the
top of the errorPage and still it is treated as error page. Can somebody
guide me to understand the issue.


Thanks again!
Atul Sawant
Ranch Hand

Joined: Jul 06, 2006
Posts: 304
This is because you are declaring errorpage.jsp in Deployment Descriptor as the official error page to be displayed when an Arithmitic exception is thrown.


Mission SCWCD. Mission SCJP Complete: SCJP 1.4 - 91%
Niranjan Deshpande
Ranch Hand

Joined: Oct 16, 2005
Posts: 1277
cool....chandra...happy that things worked..

keep doing !
Chandra Bhatt
Ranch Hand

Joined: Feb 28, 2007
Posts: 1707
Hi Atul,


It means if I define official error page in the DD, and don't add the page
directive <%@ page isErrorPage="true"%> on the errorPage, it will be
treated as errorPage.

It sounds not OK as per it is written in HFSJ page 461 Note: the exception
implicit object is available ONLY to error pages with an explicitly- defined
page directive <%@ page isErrorPage="true"%>



Or I may miss to understand the above note of the HFSJ.

Please confirm!

Thanks Atul for paying attention to this thread!

With Regards,
[ June 03, 2007: Message edited by: Chandra Bhatt ]
 
Consider Paul's rocket mass heater.
 
subject: Exception: c:catch doubt