You are returning x before you exit try. I would do this:
public class TryCatchTest {
public static void main(String[] args) {
System.out.println(test());
}
static int test() {
int x = 1;
try {
do something with x.
} finally {
do something that will happen even in case of error;
x = x + 1;
return x;
}
}
}