Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Want my exceptions to be caught by errorPage JSP ?

 
Pho Tek
Ranch Hand
Posts: 782
Chrome Python Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
maha anna
Ranch Hand
Posts: 1467
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes. Custom exceptions can also be caught by error page.
regds
maha anna
 
Pho Tek
Ranch Hand
Posts: 782
Chrome Python Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1467
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic