feat(commons): wrap IO exception in UncheckedIOException instead of generic RuntimeException

This commit is contained in:
Johannes Frohnmeyer 2024-04-03 17:20:19 +02:00
parent b4ffad5c2c
commit 067f3b9de9
Signed by: Johannes
GPG Key ID: E76429612C2929F4
1 changed files with 5 additions and 1 deletions

View File

@ -3,6 +3,8 @@ package io.gitlab.jfronny.commons.throwable;
import org.jetbrains.annotations.Contract;
import org.jetbrains.annotations.NotNull;
import java.io.IOException;
import java.io.UncheckedIOException;
import java.util.Objects;
import java.util.function.*;
@ -129,6 +131,8 @@ public class Try {
@Contract(pure = true)
protected static @NotNull RuntimeException runtimeException(@NotNull Throwable t) {
Objects.requireNonNull(t);
return t instanceof RuntimeException e ? e : new RuntimeException(t);
return t instanceof RuntimeException e ? e
: t instanceof IOException e ? new UncheckedIOException(e)
: new RuntimeException(t);
}
}