我有一个使用Realm(不知道概念)类的SWT / JFace应用程序作为线程运行主程序。我试图用我的主代码中的try / catch块来捕获任何未捕获的异常:
public static void main(String args[]) {
// ref: http://forums.instantiations.com/viewtopic.php?f=1&t=1583
Realm.runWithDefault(SWTObservables.getRealm(display), new Runnable() {
public void run() {
try {
PropertyConfigurator.configure("log4j.properties");
MainWindow window = new MainWindow();
window.setBlockOnOpen(true);
window.open();
Display.getCurrent().dispose();
} catch (Exception e) {
MessageDialog.openError(null, "Error", "Error occurred: " + e.getMessage());
logger.error("Error!!!", e);
e.printStackTrace();
}
}
});
}错误将返回到window.open()行,但会传递到Realm,所以catch块永远不会到达。以下是堆栈跟踪的结尾:
at org.eclipse.jface.window.Window.runEventLoop(Window.java:825)
at org.eclipse.jface.window.Window.open(Window.java:801)
at com.ism.MainWindow$1.run(MainWindow.java:210)
at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
at com.ism.MainWindow.main(MainWindow.java:204)
在这种情况下如何捕获所有的异常?