Is there any way to throw an Exception while using a consumer in java 8?
For example:
private void fooMethod(List<String> list) throws Exception {
list.forEach(element->{
if(element.equals("a")) {
throw new Exception("error!");
}
});
}
This gives me a compiler error saying: Unhandled exception type Exception
What is the correct way to throw an exception in this case?