public class Main {
static int method() {
for (int i = 0; i < 5; i++) {
System.out.println("i = " + i);
try {
if (i == 1) {
throw new Exception();
}
} catch (Exception e) {
System.out.println("Exception!");
return i;
} finally {
System.out.println("Finally block");
}
}
return -1;
}
public static void main(String[] args) {
System.out.println("method() returned " + method());
}
}
i = 0
i = 1
Exception!
Finally block
method() returned 1
i = 0
Finally block
i = 1
Exception!
Finally block
method() returned 1
i = 0
i = 1
Exception!
method() returned -1
Код не выполнится, произойдет ошибка компиляции