【发布时间】:2014-05-22 07:13:28
【问题描述】:
我有以下代码。
Future<Integer> future = Executor.execute(callable);
Integer i;
try {
i = future.get();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
return MESSAGE_INT_CODE;
} catch (ExecutionException e) {
// TODO Auto-generated catch block
//e.printStackTrace();
}
return i;
其中ExecutionException 可以包含其他异常,例如ABCException。
我的调用代码正在捕获ABCException,这是运行时异常,所以如果发生ExecutionException,我怎么知道是因为ABCException?
ExecutionException 在我的 public call() 方法运行时出现异常。并且调用方法可能有一些ABCException
我应该这样写吗?
catch (ExecutionException e) {
throw new ABCException(e.getMessage());
// TODO Auto-generated catch block
//e.printStackTrace();
}
【问题讨论】:
-
您所说的“
ExecutionException可以在哪里出现其他异常”是什么意思?可以是其他一些例外吗?可以包含 其他一些异常吗?您的问题目前还不清楚。 -
@jon sorry..its typo..executionException 由于我的公共 call() 方法运行时出现一些异常。并且调用方法可能有一些 ABCException
标签: java exception concurrency future callable