Java exception not caught?

From the Java Language Specification 14.20.2.:

If the catch block completes abruptly for reason R, then the finally block is executed. Then there is a choice:

  • If the finally block completes normally, then the try statement completes abruptly for reason R.

  • If the finally block completes abruptly for reason S, then the try statement completes abruptly for reason S (and reason R is discarded).

So, when there is a catch block that throws an exception:

try {
    // ...
} catch (Exception e) {
    throw new Exception("2");
}

but there is also a finally block that also throws an exception:

} finally {
    throw new Exception("3");
}

Exception("2") will be discarded and only Exception("3") will be propagated.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)