Naj Shrin wrote:
Sorry, I don't see what needs initializing, its a throw command with an instance of this simple Exception:
Is it illegal to nest another try within a finally block?
For local variables, you are required to initialize the variable before you can use it. And the compiler will check every possible path -- if there is a path from declaration to usage without it ever being set (ie. initialized), the compiler will complain.
In this case, the compiler doesn't know that the f() method will always throw the exception, hence, the path is from the try block to the finally block -- with no exception being thrown.
from compiler point of view,
if function f() does not throw any exception then control will never reach to catch block and e1 will never be initialized. In that case in finally block e1 is used which is local to main method and not initialized. That is why compiler is complaining.