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: 
Surely the simplest, and least hacky approach is just to use a temporary variable...

```
final int x;

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

```

Simple.
Logically, why would you want to do something with `x` if `blah()` had failed? `x` would be uninitialized and this can be dangerous, and so Java prevents this. It's helping you in ways older languages like c would not. So move the `println` inside would be the obvious solution.

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

```

I think SRP could apply here, depending on your actual code, exception catching is arguably a responsibility, so I might split this one method into two. One that doesn't care about handling, and one that only handles.

```
public void doBlah throws MyPanicException {
    final int x = blah(); 
    System.out.println("x is " + x);
}

public void tryBlahOrDie {
    try{
      doBlah();
    } catch (MyPanicException e) {
        abandonEverythingAndDie();
    }
}

```