Subscribe

RSS Feed (xml)

Powered By

Skin Design:
Free Blogger Skins

Powered by Blogger

Saturday, December 1, 2007

How to Deal with the errors in java

// generateError.jsp
<%@ page errorPage="processError.jsp" %>
<%-- Declare the page to send errors to --%>
<%-- After clicking the button, it will call itself again the generate error --%>


<%-- This scriptlet checks a hidden field to see whether or not to throw an exception --%>
<%
String hiddenField = request.getParameter("hiddenValue");
if ( hiddenField.equals("error"))
throw new java.lang.NullPointerException();


%>


Generate Error

This page generates an error when you click the button.









//Another JSP file: processError.jsp
<%@ page isErrorPage="true" %>


Process Error

<% if ( exception != null ) {
out.write("\nAn error occurred. This page is to tell you what you did wrong.\n");
}
else {
out.write("\nYou have reached this page, but no error information is available.\n");
}
%>

No comments: