Error handling – Apple WebObjects 3.5 User Manual

Page 154

Advertising
background image

Chapter 9

Deployment and Performance Issues

154

Error Handling

When an error occurs, WebObjects by default returns a page containing
debugging information and displays that page in the web browser. This
information is useful when you’re in the debugging phase, but when you’re
ready to deploy, you probably want to make sure that your users don’t see such
information.

The WOApplication class (WebApplication in Java) provides the following
methods that you can override to show your own error page.

For example, the following implementation of

handleException:

returns a

component named ErrorPage whenever an error occurs in the application.

public Response handleException(java.lang.Throwable anException) {

Response response = new Response();
Request request = context().request();
String newURL = "http://" + request.applicationHost() +

request.adaptorPrefix() + "/" + request.applicationName() +
".woa/-/ErrorPage.wo";

response.setHeader(newURL, "location");
response.setHeader("text/html", "content-type");
response.setHeader("0", "content-length");
response.setStatus(302);

return response;

}

Notice that this method, and all of the error-handling methods, return a
WOResponse object instead of a WOComponent object. It creates the response
by directly setting the URL in the HTTP header to point to the component that
it wants to return (in this case, the component is named ErrorPage). Notice how
you can retrieve much of the information about the application URL through
the current request object, which you can access from the current context
object.

Method

Invoked When

handleSessionCreationError

The application needs to create a new session but can’t.

handleSessionRestorationError

The application receives a request from a session that has timed out.

handlePageRestorationError

The application tries to access an existing page but cannot. Usually, this occurs

when the user has backtracked beyond the limit set by

setPageCacheSize:

and

setPageRefreshOnBacktrackEnabled:

is NO.

handleException:

The application receives an exception; that is, any general type of error has
occurred.

Advertising