pivovarit / throwing-function

Checked Exceptions-enabled Java 8+ functional interfaces + adapters

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

This library seems useless for methods with throws Throwable

rwperrott opened this issue · comments

To start with, I think that SneakyThrowUtil::sneakyThrows should be changed from:

    static <T extends Exception, R> R sneakyThrow(Exception t) throws T {
        throw (T) t;
    }

to

    static <T extends Exception, R> R sneakyThrow(Throwable t) throws T {
        throw (T) t;
    }

and all the other code should be modified to accept Throwable, not letter extends Exception, because this blocks capture of the unchecked Error sub-class of Throwable, thus making this library unusable for methods which annoyingly have throws Throwable method signatures e.g. java.lang.invoke.MethodHandle::invoke* methods.

Often Errors should not be caught, because they can signal a fatal failure which should be allowed to propagate, just as sneaky throwing methods allow bypassing the mistake of checked Exceptions, which should not be caught yet either.

I've forked this project, and on my local copy it looks like replacing letter extends Exception, with letter extends Throwable, on the functional class type parameters works, assume that this type is actually used e.g. not for ThrowingSupplier *.

  • IntelliJ IDEA seems, mostly, good at spotting redundant/iffy stuff like this.

That makes sense. Will give it a longer thought later, and most likely include with the next release

I've made my suggested changes in my fork at https://github.com/rwperrott/throwing-function for this issue and issue 80, and it builds locally.

Closing for same reason as other close.