Programming__WebObjects-Web Applications-Development-Custom Error Handling

Version 1.1 by smmccraw on 2007/07/08 09:45

Exception Page

To provide a custom error handler when an exception is thrown, override the method:

  public WOResponse handleException (java.lang.Exception anException, WOContext aContext) { }

For example:

  public WOResponse handleException(Exception _exception, WOContext _context) {
    Session session = (Session) _context.session();
    do something to notify user of exception, maybe put a message in the session here ...
    WOResponse response;
    if (/* you can't handle exception*/) {
      response = super.handleException(_exception, _context);
    }
    else {
      response = pageWithName(YourExceptionPage.class.getName(), _context).generateResponse();
    }
    return response;
  } 

Session Expired

To provide a custom error handler when an exception is thrown, override the method:

  public WOResponse handleSessionRestorationErrorInContext(WOContext _context) {

For example:

    
  public WOResponse handleSessionRestorationErrorInContext(WOContext _context) {
    Session session = (Session) _context.session();
    do something to notify user of exception, maybe put a message in the session here ...
    WOResponse response = pageWithName(YourErrorPage.class.getName(), _context).generateResponse();
    return response;
  }

Your Request Produced an Error

Chuck Hill

This message started to appear in WO 5.2 when an exception was raised in a DirectAction, but only in deployed applications. Here is what is happening:

WODisplayExceptionPages
true or false to enable or disable the generation of WOExceptionPages for direct action requests. Default is true in development mode and false in deployment mode.

From http://developer.apple.com/documentation/WebObjects/WOAppProperties/AppProperties/chapter_1_section_1.html

If the page being returned throws during appendToResponse and the app is deployed, all that is displayed is a blank page with the words "Your request produced an error".

To avoid this, either add this to the launch agruments:

  -DWODisplayExceptionPages=true

Or change the main method in your Application class to look like this:

  public static void main(String argv[]) {
    System.setProperty("WODisplayExceptionPages", "true");
    WOApplication.main(argv, Application.class);
  }

This won't work if you put it in the constructor.

Category:WebObjects