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.
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.
Table of Contents Next Section