*
The moose likes Servlets and the fly likes Want my exceptions to be caught by errorPage JSP ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Want my exceptions to be caught by errorPage JSP ?" Watch "Want my exceptions to be caught by errorPage JSP ?" New topic
Author

Want my exceptions to be caught by errorPage JSP ?

Pho Tek
Ranch Hand

Joined: Nov 05, 2000
Posts: 761

Will throwing my own exceptions within scriplets be caught by the JSP specified by my errorPage attribute ?

<%@ page errorPage="error.jsp"%>
<%

throw (new IllegalArgumentException("parameter xxx required"));

%>
Thanks
Pho

Regards,

Pho
maha anna
Ranch Hand

Joined: Jan 31, 2000
Posts: 1467
Yes. Custom exceptions can also be caught by error page.
regds
maha anna
Pho Tek
Ranch Hand

Joined: Nov 05, 2000
Posts: 761

I tried to throw a simple exception and got the error:
Unable to compile class for JSPC:\jakarta-tomcat-3.2.1\work\localhost_8080%2Fjspadmin\_0002fcsr_0002fAccountBillto_0002ejspAccountBillto_jsp_0.java:229: Statement not reached. out.write("\r\n"); ^ 1 error
Note that I am doing this inside an include file. And the including file is specifying the errorPage.
e.g.

Thanks
Pho
[This message has been edited by Pho Tek (edited May 16, 2001).]
maha anna
Ranch Hand

Joined: Jan 31, 2000
Posts: 1467
I suspect the error is more related to your coding logic than throwing exceptions. Somewhere in your code a "return" or "throw someException" is there which is in "definite execute" path. There are some code under those return/throw kind of statement which can not be reached. So the compiler throws this error.
Please post your code.
regds
maha anna
[This message has been edited by maha anna (edited May 16, 2001).]
saravanakumar sundaram
Greenhorn

Joined: May 16, 2001
Posts: 5
Please find below some code on exception errorpage JSP.
Errorpage.jsp
--------------
<%@ page isErrorPage="true" %>
<html>
<body>
<h1>
Error Page
</h1>
<hr>
<h2>
Received the exception:<br>
<font color=red>
<%= exception.toString() %>
</font>
</h2>
</body>
</html>
Errorhandler.jsp
----------------
<%@ page errorPage="errorpage.jsp" %>
<html>
<body>
<form method=post action="errhandler.jsp">
What's the coolest programming language in the known universe?<p>
Java<input type=radio name=language value="JAVA" checked>
C++<input type=radio name=language value="CPP">
Visual Basic<input type=radio name=language value="VB">
<p>
<input type=submit>
</form>
<%
if (request.getMethod().equals("POST")) {
if (request.getParameter("language").equals("JAVA")) {
out.println("<hr><font color=red>You got that right!</font>");
} else {
throw new Exception("You chose the wrong language!");
}
}
%>
</body>
</html>
May be this could help you.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Want my exceptions to be caught by errorPage JSP ?