如何获取匿名runnable
以使父方法抛出异常?
public boolean drive2Exit() throws Exception {
while(true) {
handler.postDelayed(new Runnable() {
public void run() {
try {
...
catch (Exception e) {
//drive2Exit should throw exception
}
}
}, 100);
}
}
最佳答案
我认为使用 Future 可能会成为最好的服务器:
https://docs.oracle.com/javase/7/docs/api/java/util/concurrent/Future.html
使用它,您可以在主代码中检查可运行的结果,如果它抛出异常,您将在检查 future 的代码中得到要处理的异常。使用该异常,我认为嵌入的原始异常可以决定在 Future 之外抛出什么。
关于java - 如何让父方法抛出异常?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27220763/