Development-Custom Error Handling

Last modified by Ray Kiddy on 2021/04/22 20:40

Exception Page

To provide a custom error handler when an exception is thrown, override this WOApplication 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Ā https://developer.apple.com/library/archive/documentation/WebObjects/WOAppProperties/Articles/ApplicationProperties.html#//apple_ref/doc/uid/TP40005337-SW1

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:

Unknown macro: noformat. Click on this message for details.

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.