research this code:
public class TestFinalAndCatch {
private final int i;
TestFinalAndCatch(String[] args) {
try {
i = method1()
To overcome this problem, use a local variable in the try catch block and then assign that result to the instance variable.
public class TestFinalAndCatch {
private final int i;
TestFinalAndCatch(String[] args) {
int tmp;
try {
tmp = method1();
} catch (IOException ex) {
tmp = 0;
}
i = tmp;
}
static int method1() throws IOException {
return 1;
}
}