Can you please explain why checked exceptions have to be caught from within lambda expressions? In other words, why does the following code not compile...
pu
The issue isn't the lambda expression, it's the interface it's implementing. Remember, a lambda expression is basically just shorthand for an anonymous class that implements a given interface.
In this case, forEach takes a java.util.function.Consumer:
public interface Consumer {
void accept(T t);
...
}
Note that accept is not declared to throw anything. This means that no implementation of it can throw anything; not a named class, not an anonymous class, and not a lambda.