Search code examples
javascjpopen-closed-principle

Exceptions and errors report order


What rules applies to the following code:

    try {
        assert (false) : "jane";
    } catch (Exception e2) {
        System.out.print("ae2 ");
    } finally {
        throw new IllegalArgumentException();
    }

Assetions are enabled.

Why IllegalArgumentException is reported instead of AssertionError? Are there any rules which applies in this situations?

Edit: Sorry! in this example there should be assert (false)


Solution

  • An uncaught exception in a finally block (or in a catch block) causes any exception from the try block to be discarded. See the Java Language Specification § 14.20 for details. As of Java 7, an enclosing try/catch block can recover discarded exceptions (as described here).