Java Multi Catch/Rethrow

If I do the following using a multi-catch in Java 1.7:

catch (ArrayIndexOutOfBoundsException | NullPointerException ex) {
    logger.error("Array out of bounds exception in BatchTableRow constructor: data was: table = " +
            schema.toString() + ", data: " + sourceRow.toString(), ex);
    throw ex;
}

Will the re-thrown exception maintain the exception type that originally entered the catch clause? What if I catch 3 kinds of exceptions including the base "Exception" class - will it always remain the most specific one available in the list?

Jon Skeet
people
quotationmark

Will the re-thrown exception maintain the exception type that originally entered the catch clause?

Yes - it will rethrow the exact same exception object. You need to differentiate between the compile-time type of ex (which is effectively the upper bound of the declared types) and the execution-time type of the value of ex, which is a reference to a specific object. The object's type won't change just because you've caught the exception.

people

See more on this question at Stackoverflow