java runnable 异常_Java(SWT / JFace) - 处理Runnable中的所有异常

我有一个使用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)

在这种情况下如何捕获所有的异常?

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值