Does anyone know why throwing a Throwable or an Exception in a Stream doesn't compile in the code below?
Environment: Win 10 x64, Eclipse 2020-03, openJDK v14
public void myMethod(final boolean myBoolean) throws Throwable {
if (myBoolean) {throw new Exception("Compiler accepts this OK");}
if (myBoolean) {throw new Throwable("Compiler accepts this OK");}
Stream.of("").forEach(s -> {throw new Error("");});
Stream.of("").forEach(s -> {throw new RuntimeException("");});
Stream.of("").forEach(s -> {throw new Exception("Compiler -> Unhandled exception type Exception");});
Stream.of("").forEach(s -> {throw new Throwable("Compiler -> Unhandled exception type Throwable");});
}
I've declared that the Method throws Throwable & outside the Stream it compiles ok, but inside, it seems I can only throw subclasses of Error & RuntimeException.