Question: Before you say that this question has already been answered tons of times, here is my code snippet:

```
final int x;
try {
    x = blah(); 
} catch (MyPanicException e) {
    abandonEverythingAndDie();
}
System.out.println("x is " + x);

```

If invoking `abandonEverythingAndDie()` has the effect of ending the execution of the whole program (say because it invokes `System.exit(int)` ), then `x` is always initialized whenever it is used. 

Is there a way in the current Java language to make the compiler happy about variable initialization, by informing it that `abandonEverythingAndDie()` is a method which never returns control to the caller? 

I do **not** want to 

* remove the `final` keyword
* initialize `x` while declaration,
* nor to put the `println` in the scope of the `try...catch` block.

Answer: 
Not without cheating a little by providing a little bit of extra information to the compiler:

```
final int x;
try {
    x = blah();
} catch (MyPanicException e) {
    abandonEverythingAndDie();
    throw new AssertionError("impossible to reach this place"); // or return;
}
System.out.println("x is " + x);

```

You can also make `abandonEverythingAndDie()` return something (only syntactically, it will of course never return), and call `return abandonEverythingAndDie()`:

```
final int x;
try {
    x = blah();
} catch (MyPanicException e) {
    return abandonEverythingAndDie();
}
System.out.println("x is " + x);

```

and the method:

```
private static <T> T abandonEverythingAndDie() {
    System.exit(1);
    throw new AssertionError("impossible to reach this place");
}

```

or even

```
throw abandonEverythingAndDie();

```

with

```
private static AssertionError abandonEverythingAndDie() {
    System.exit(1);
    throw new AssertionError("impossible to reach this place");
}

```
No, the compiler only checks that your code is legal. In this context, `abandonEverythingAndDie` is treated as a blackbox and the compiler considers that not all branches cover the initialization of the variable. Even the below code is not accepted by the compiler:

```
final int x;
try {
    x = blah(); 
} catch (MyPanicException e) {
    abandonEverythingAndDie();
    System.exit(-1); // the System.exit() itself is treated as a blackbox :)
}
System.out.println("x is " + x);

```

In other words, the compiler does not "think" about the possible dynamic execution in order to compile the program.