WebObjects/Web 应用程序/开发/自定义错误处理
外观
要提供在抛出异常时处理自定义错误的处理程序,请覆盖该方法
public WOResponse handleException (java.lang.Exception anException, WOContext aContext) { }
例如
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;
}
要提供在抛出异常时处理自定义错误的处理程序,请覆盖该方法
public WOResponse handleSessionRestorationErrorInContext(WOContext _context) {
例如
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;
}
当在 DirectAction 中引发异常时,此消息从 WO 5.2 开始出现,但仅在已部署的应用程序中出现。以下发生了什么
WODisplayExceptionPages true 或 false 用于启用或禁用为直接操作请求生成 WOExceptionPages。默认情况下,在开发模式下为 true,在部署模式下为 false。
如果要返回的页面在 appendToResponse 期间抛出,并且应用程序已部署,则只会显示一个空白页面,其中包含“您的请求产生了错误”几个字。
要避免这种情况,请将此内容添加到启动参数中
-DWODisplayExceptionPages=true
或者将应用程序类中的 main 方法更改为如下所示
public static void main(String argv[]) {
System.setProperty("WODisplayExceptionPages", "true");
WOApplication.main(argv, Application.class);
}
如果您将其放在构造函数中,则此方法无效。