Introduction

System errors are unexpected and usually cause unrecoverable damage to a transaction. Examples of system error are: file system out of space, out of memory exception and database connection timeout.

Basic Guidelines

Follow a simple set of guidelines to report system error.

  1. Avoid complicated logic in the error display page. You want to make sure that the error pages have a very high probability of functioning when drastic errors are occuring elsewhere in the system. In most cases, static HTML error pages are preferred.
  2. Provide a phone number or e-mail in the error page for the user to contact the web master and report the problem.
  3. Do not display details such as stack trace in the error page. Use Log4J or a similar system to store the error details in a log file.

J2EE and WebSphere

J2EE lets us specify a URI (for HTML, JSP or Servlet) for an HTTP error code in the web.xml file. This helps us report problems such as 404 file not found and 401 authorization failed. Imprtant: If you are associating a URI for the 401 error code, make sure that the URI is unprotected.

WebSphere extension allows us to specify a catch all URI that is invoked when the web container catches an exception thrown from a Servlet or JSP.

Developing System Error Pages

WebSphere Studio Application Developer (WSAD) makes it easy to develop error pages and configure the web deployment descriptor.

Open the deployment descriptor by double clicking on the web.xml file. Click on the Pages tab. In the Error Pagessection click on Add. Enter an HTTP error code and URI or select them from a list.

To specify the catch all error page, click on the Extensions tab. In the Default error page field, enter the JSP or HTML file name or click on Browse to pick the file name from a list.

REPORTING SYSTEM ERRORS

Save the deployment descriptor settings.

Test

Create two sets of error conditions:

  1. HTTP error condition such as 404 file not found and 401 authorization failed. Make sure that the designated error reporting pages are getting displayed.
  2. Application code error condition such as unhandled exception thrown froma JSP, ServletException from a Servlet and JSP compilation problem. Make sure that the catch all error page is getting displayed. Detail error message will be logged in the standard output file of the application server (or, console in case of WSAD).

Conclusion

System error pages are important customer service tools. You want to make sure that they are available under all conditions and contain useful information. This article shows you how to report system errors in a reliable fashion by leveraging the J2EE standard and WebSphere extensions.