Why must throw statements be enclosed with a full code block in a lambda body? [duplicate]

AFAIK The jls says that the lambda body has to be:

expression or a block. Having it like this:

new Thread(() -> throw new RuntimeException());

is neither and the compiler somehow informs you about that.

Declaring it like this:

 new Thread(() -> {
     throw new RuntimeException();
 });

makes it a block. Here is the relevant part:

A block is a sequence of statements, local class declarations, and local variable declaration statements within braces.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)