vavr icon indicating copy to clipboard operation
vavr copied to clipboard

Remove sneakyThrow

Open danieldietrich opened this issue 3 years ago • 2 comments

There was some prior discussion about safety. A Java dev isn’t expecting a checked exception to be sneaky thrown, especially if it isn’t declared on the method signature.

Sneaky throw is an undocumented hack that isn't intended to be used. We can't guarantee that it will still work in future Java versions.

We would revert back the old state and throw exceptions wrapped in a non-fatal RuntimeException. (Alternatively we could declare throws Throwable on Try.get() but that would make the Try API questionable.)


See also #2380. I did that on the 1.0 branch, which is stale. Actual work takes place on master (maybe we should rename it to main).

Sneaky throw was introduced with Vavr 0.9.0. Here is the PR that added it. Especially, we removed the Fatal and NonFatal exception wrappers in Try. There have been additional additions regarding sneaky throw, like this commit.

The code base has changed, it isn't as simple as just reverting the previous commits.

danieldietrich avatar May 23 '21 11:05 danieldietrich

Dear Daniel Dietrich (@danieldietrich),

It would be great to have this issue resolved and released.

Best regards, Sergey Vyacheslavovich Brunov.

svbrunov avatar Jul 01 '21 12:07 svbrunov

ExceptionUtils.rethrow might be a suitable alternative.

Edit: Nevermind, I see the problem now: https://github.com/vavr-io/vavr/issues/2380#issuecomment-475313757

rkrisztian avatar May 25 '22 11:05 rkrisztian