如何处理java.util.concurrent.ExecutionException异常? [英] how to handle java.util.concurrent.ExecutionException exception?
本文介绍了如何处理java.util.concurrent.ExecutionException异常?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的代码的一部分是抛出java.util.concurrent.ExecutionException异常。
我该如何处理?我可以使用throws子句吗?我有点新的java。
Some part of my code is throwing java.util.concurrent.ExecutionException exception. How can I handle this? Can I use throws clause? I am a bit new to java.
推荐答案
如果你正在处理异常,事情是非常简单的。 p>
If you're looking to handle the exception, things are pretty straightforward.
public void exceptionFix1() {
try {
//code that throws the exception
} catch (ExecutionException e) {
//what to do when it throws the exception
}
}
public void exceptionFix2() throws ExecutionException {
//code that throws the exception
}
请记住,第二个例子将被封装在一个 try-catch
块中的某个地方执行层次结构。
Keep in mind that the second example will have to be enclosed in a try-catch
block somewhere up your execution hierarchy.
如果你想修复例外,我们必须看到更多的代码。
If you're looking to fix the exception, we'll have to see more of your code.
这篇关于如何处理java.util.concurrent.ExecutionException异常?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文