Find the exception that gets caught

Original question

Given the following method, which is part of the library (therefore, it cannot be edited) (also, it A()is closed, therefore, it cannot be called outside m()):

void m() {
    try {
        A();
    } catch (Exception e) {
        B();
        throw e;
    }
}

When called m(), it is A()generated Exception eand therefore executed B(). However, it B()also throws an exception, which is then thrown (instead of ewhich will be thrown later).

Is it possible to find Exception e? Perhaps using some kind of smart reflex or a multi-threaded approach to pause and move?

An explanation of why I chose the best answer, and what else could be useful

Makoto's answer:

e is lost because any exception thrown will cause a sudden termination of execution.

- (.. Exception e).

, :

, - catch.

Pinkie Swirl:

, e ( ..)

: (, , SQLException, , ).

+4
2

e , .

( ):

void m() throws Exception {
    try {
        A();
    } catch (Exception e) {
        B();
        throw e;
    }
}

private void B() {
    throw new RuntimeException("No!!!!");
}

private void A() throws Exception {
    throw new RuntimeException("Do I make it??");
}

, B(), m(), . , e.

, catch...

void m() throws Exception {
    try {
        A();
    } catch (Exception e) {
        throw e;
        B();
    }
}

... B() , , B() . , , , B() .

+3

, . Intellij , , .

throw.

+1

Source: https://habr.com/ru/post/1612147/


All Articles