PATH |
Customizing the Default Error Behavior
Description
By default, WebObjects displays a standard error page in the browser when an application error occurs. This page provides useful debugging information, but generally shouldn't be seen by end users of the application. Most deployed sites use one or more custom error pages.
Custom error pages can be provided in your application in two ways. The first way is to replace the default WOExceptionPage component. While this method requires no coding, it causes all WebObjects applications to display your custom page when an error occurs. Another way to provide custom error behavior is to override the exception handlers in the WOApplication class. Although this method requires some coding, it can display different error pages for different types of exceptions, and it does not affect the behavior of other WebObjects applications.
Replacing the WOExceptionPage Component
The default WebObjects error page is defined in $NEXT_ROOT\Library\Frameworks\WOExtensions.framework\Resources\WOExceptionPage.wo . This component may be edited using WebObjects Builder. You should make a backup copy before you modify the default WebObjects error page.
Overriding the WOApplication Exception Handlers
The WOApplication class provides the following methods that you can override to show your own error page. These methods return a WOResponse object, which your code needs to provide. The example code shows how to override these exception handling methods and redirect WebObjects to different pages depending on the type of exceptions that occur.
Exception handler (Java)
public WOResponse handleException (java.lang.Throwable anException, WOContext aContext) { WOComponent errorPage; String exceptionDescription = anException.toString(); if (exceptionDescription.indexOf("EOValidationException") > -1) { System.err.println ("validation error"); errorPage = pageWithName("ValErrorPage",aContext); } else { System.err.println ("error" + exceptionDescription); errorPage = pageWithName("ErrorPage",aContext); } WOResponse response = errorPage.generateResponse(); return response; }
See Also
- Understanding the Default WebObjects Error Page
- WOApplication class specification in the WebObjects Framework Reference
- WOResponse class specification in the WebObjects Framework Reference
Revision History
22 July, 1998. John Malach. First Draft.
© 1999 Apple Computer, Inc.