aspose file tools*
The moose likes JSP and the fly likes how to properly catch/display exception in jsp ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "how to properly catch/display exception in jsp ?" Watch "how to properly catch/display exception in jsp ?" New topic
Author

how to properly catch/display exception in jsp ?

Ian Yang
Ranch Hand

Joined: Nov 27, 2001
Posts: 44
I have a scenario that "MyServlet.java" do a "forward(req, res)" to "My.jsp". "MyServlet.java" code throws ServletException, IOExcpetion, plus since "MyServlet.java" calls other database codes which throws SQLException, so I let "MyServlet.java" also throws SQLException.
I want to catch ALL of the above exceptions in "My.jsp" page by using
<%@ page errorPage="error.jsp" %>
The in "error.jsp" page, I use
<%= exception.getMessage() %>
to display the exception.

Now the question is:
1. Does this work ?
2. Does the <%=exception.getMessage() %> show what type of error it is ? i.e. if it is a SQLException, does it show it is SQL exception in the message content ?
Thanks,
Ian
Ian Yang
Ranch Hand

Joined: Nov 27, 2001
Posts: 44
sorry one correction for my own post, what my "doGet(req, res)" method throws is ServletException, IOException, and my own customized exception (instead of SQLException which is not allowed to be put here).
Maulin Vasavada
Ranch Hand

Joined: Nov 04, 2001
Posts: 1871
about the second question i'm sure it will determine run time type of the exception and print appropriate type. this is SCJP question.
about the first question, i didn get u. y it will not work? it will thats why u 've errorPage mechanism in the JSP..
regards
maulin
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: how to properly catch/display exception in jsp ?