failsafe-lib / failsafe

Fault tolerance and resilience patterns for the JVM
https://failsafe.dev
Apache License 2.0
4.2k stars 297 forks source link

Add non-wrapped exceptions to get() #236

Open Gaibhne opened 4 years ago

Gaibhne commented 4 years ago

We talked about this a few days ago; basically, it allows you to properly catch an Exception thrown from code you call in a lambda, like so:

public void testCheckedException() throws IOException {
    RetryPolicy<Object> retryPolicy = new RetryPolicy<>();

    Failsafe.with(retryPolicy).getWithException(() -> {
        throw new IOException();
    });
}

or

RetryPolicy<Object> retryPolicy = new RetryPolicy<>();

try {
    Failsafe.with(retryPolicy).getWithException(() -> {
        throw new IOException();
    });
} catch (IOException e) {
    e.printStackTrace(); // this is horrible practice
}

Obviously the code is not intended to be accepted like this, it's just a POC.

coveralls commented 4 years ago

Coverage Status

Coverage decreased (-1.8%) to 90.593% when pulling 1dc0c8d95b977329c07cc3de884d01f57387ec6b on Gaibhne:master into 7f411c65dfb29e1b4679a269796a5d1632c8acfc on jhalterman:master.