Skip to content

Commit

Permalink
Modify SuspendedException to subclass Throwable rather than RuntimeEx…
Browse files Browse the repository at this point in the history
…ception (#124)
  • Loading branch information
slinkydeveloper authored Oct 26, 2023
1 parent fe4bf82 commit 0ee6f08
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
package dev.restate.sdk.core;

public final class SuspendedException extends RuntimeException {
public final class SuspendedException extends Throwable {
@SuppressWarnings("StaticAssignmentOfThrowable")
public static final SuspendedException INSTANCE = new SuspendedException();

@SuppressWarnings("unchecked")
public static <E extends Throwable> void sneakyThrow() throws E {
throw (E) SuspendedException.INSTANCE;
}

private SuspendedException() {
super("SuspendedException");
setStackTrace(new StackTraceElement[] {});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ static <T> T awaitCompletableFuture(CompletableFuture<T> future) {
try {
return future.get();
} catch (InterruptedException | CancellationException e) {
throw SuspendedException.INSTANCE;
SuspendedException.sneakyThrow();
return null; // Previous statement throws an exception
} catch (ExecutionException e) {
throw (RuntimeException) e.getCause();
}
Expand Down

0 comments on commit 0ee6f08

Please sign in to comment.