Sobes.tech
Junior — Senior

Determining the output when re-throwing exceptions in nested try-catch-finally blocks

livecode

Task condition

It is necessary to predict what text will be printed to the console when executing a program containing nested try‑catch‑finally blocks with re-throwing exceptions.

main {
    try {
        System.out.println("1");
        throw new RuntimeException("my own Exception");
    } catch (RuntimeException e) {
        System.out.println("2");
        throw new RuntimeException("my second Exception");
    } catch (Exception e) {
        System.out.println("3");
    } finally {
        System.out.println("4");
    }

    System.out.println("finish");
}