假设我有一个类和一个方法
class A {
void foo() throws Exception() {
...
}
}
现在我想为流传递的每个A
实例调用foo:
void bar() throws Exception {
Stream<A> as = ...
as.forEach(a -> a.foo());
}
问题:如何正确处理异常?我的代码在我的电脑上无法编译,因为我没有处理foo()可能抛出的异常。这里bar
的throws Exception
似乎毫无用处。为什么会这样呢?