代码
class TestException extends Exception {
}
interface Task<E extends Exception> {
void call() throws E;
}
public class TaskPerformer {
/** performs a task in the proper context, rethrowing any exceptions the task declares */
private <E extends Exception> void perform(Task<E> task) throws E {
beforeTask();
try {
task.call();
} finally {
afterTask();
}
}
private void afterTask() {
// implementation elided (does not matter)
}
private void beforeTask() {
// implementation elided (does not matter)
}
public static void main(String[] args) {
new TaskPerformer().perform(() -> { // compilation error
try {
throw new TestException();
} catch (TestException e) {
return;
}
});
}
}
错误的eclipse编译器拒绝
未处理的异常类型TestException
在main的第一行,即使lambda表达式处理此异常(对吗?)。
这是编译器错误,还是我忽略了什么?