Class AsyncException

  • All Implemented Interfaces:
    Serializable

    public class AsyncException
    extends RuntimeException
    A subclass RuntimeException used to indicate problems in asynchronous code.
    See Also:
    Serialized Form
    Implementation Note:
    Sadly, we cannot make the CompletableFuture generic. It will not compile, and the compiler reports the following error: "a generic class may not extend java.lang.Throwable". However, we can fake it by declaring getFuture() in a generic manner (and suppressing the unchecked warning). This means you could still receive a ClassCastException at runtime if you attempt a cast to an invalid type.
    • Constructor Detail

      • AsyncException

        public AsyncException​(String message,
                              @Nullable
                              CompletableFuture future)
        Construct instance with given message and future.
        Parameters:
        message - the exception message
        future - the CompletableFuture that caused the error, may be null
      • AsyncException

        public AsyncException​(String message,
                              Throwable cause,
                              @Nullable
                              CompletableFuture future)
        Construct instance with given message, cause, and future.
        Parameters:
        message - the exception message
        cause - the original cause of the exception
        future - the CompletableFuture that caused the error, may be null
    • Method Detail

      • getFuture

        @Nullable
        public <T> CompletableFuture<T> getFuture()
        The future which causes the exception. May be null.
        Type Parameters:
        T - the generic type of the CompletableFuture
        Returns:
        the future causing this exception, or null