2010年5月18日星期二

GWT.setUncaughtExceptionHandler

GWT设置UncaughtExceptionHandler 以捕获为捕捉的异常,这gwt在host mode编译后的JavaScript如果出现错误,No errors in Hosted Mode and Compiled localy, but deployed to tomcat yields in errors
这是恼人,加上UncaughtExceptionHandler起码有一丝线索

GWT.setUncaughtExceptionHandler(new GWT.UncaughtExceptionHandler() {
public void onUncaughtException(Throwable throwable) {
String text = "Uncaught exception: ";
while (throwable != null) {
StackTraceElement[] stackTraceElements = throwable
.getStackTrace();
text += throwable.toString() + "\n";
for (int i = 0; i < stackTraceElements.length; i++) {
text += "    at " + stackTraceElements[i] + "\n";
}
throwable = throwable.getCause();
if (throwable != null) {
text += "Caused by: ";
}
}
System.err.print(text);
text = text.replaceAll(" ", " ");
Window.alert("系统错误:"+text);
}
});

没有评论:

发表评论