use*_*818 4 java methods multithreading exception outer-join
码:
outerMethod {
@Override
public void run() {
innerMethod throws IOException
}
}
Run Code Online (Sandbox Code Playgroud)
在线程中抛出的方法抛出已检查的异常 - IOException.我需要在主线程中处理此异常.喜欢:
outerMethod() throws IOException
{
@Override
public void run() {
innerMethod() throws IOException
}
}
Run Code Online (Sandbox Code Playgroud)
这可能吗?如果不是,那么更好的方法是什么?
谢谢.
使用FutureTask http://docs.oracle.com/javase/6/docs/api/java/util/concurrent/FutureTask.html#get%28%29.它的get方法将封装可能在另一个线程上运行的任务的任何异常.
ExecutionException:尝试检索通过抛出异常而中止的任务的结果时抛出异常.可以使用Throwable.getCause()方法检查此异常.