Why does throw outerE;
generate a compilation error? I know that throw e;
should not generate a compiler error because of the precise rethrow feature.
They're the same Exception
object, but one is scoped inside the catch
block only and one is scoped outside the try-catch block.
Shouldn't neither of these generate a compiler error? Or, at least, both behave the same way?
static void preciseRethrowTest()
{
Exception outerE;
try
{
}
catch (Exception e)
{
outerE = e;
// Compilation error here. Unhandled exception type Exception
// throw outerE;
throw e; // No compiler error
}
}
I'm using Java 1.8.0_51. (Precise rethrow is introduced in Java 7)