What will be printed to standard output stream if a tryThis() method throws an IOException?

try {
    tryThis();
    return;
} catch (IOException x1) {
    System.out.println("exception 1");
    return;
} catch (Exception x2) {
    System.out.println("exception 2");
    return;
} finally {
    System.out.println("finally");
}
Explanation
Only one catch block with the most specific matching exception will be executed, in this case it is catch (IOException x1) . Finally block is also executed, as it is executed always.

Follow CodeGalaxy

Mobile Beta

Get it on Google Play
Send Feedback