Catch an exception by class?

I would like to get the exception that I expect, but allow others.

The solution I came to now:

protected void perfromCall(Class expectedException) throws Exception {
    try {
        response = call.call(request);
    } catch (Exception e) {
        if (!expectedException.isInstance(e)) {
            throw new Exception(e);
        }
    }
}

As long as it is a silent expected exception, as I would like, and throwing others, I do not like that it wraps up unexpected exceptions, and now I have to break unexpectedly in the caller, whereas earlier (before trying to silently catch the expected exceptions), I could let them go to the test platform to skip the test.

Is there a cleaner way to say: “I was expecting class A exceptions, but for any other exception, let it raise the chain until it has been processed by the test environment above”?

: , , ( ), , . , . , , - . , , .

+1
1
protected void perfromCall(Class<?> expectedException) throws Exception {
    try {
        response = call.call(request);
    } catch (Exception e) {
        if (!expectedException.isInstance(e)) {
            throw e;
        }
    }
}
+7

All Articles