Class TaskExecutionException

All Implemented Interfaces:
Serializable

public class TaskExecutionException extends RuntimeException
Defines that an asynchronously executed task has thrown an unchecked exception. This exception is the counter part of the java.util.concurrent.ExecutionException but unlike ExecutionException, the TaskExecutionException is an unchecked exception (which makes sense since the submitted tasks are not allowed to throw checked exceptions).

The cause of TaskExecutionException is the exception actually thrown by the asynchronously executed task and is never null. That is, getCause() will never returns null.

See Also:
  • Constructor Details

    • TaskExecutionException

      public TaskExecutionException(Throwable cause)
      Creates a new TaskExecutionException with a given cause. The cause defines the actual exception thrown by the asynchronously executed task.
      Parameters:
      cause - the exception thrown by the asynchronously executed task. This argument cannot be null.
      Throws:
      NullPointerException - thrown if the specified cause is null
    • TaskExecutionException

      public TaskExecutionException(String message, Throwable cause)
      Creates a new TaskExecutionException with a given cause and exception message. The cause defines the actual exception thrown by the asynchronously executed task.
      Parameters:
      message - the String to be returned by the getMessage() method. This argument is allowed to be null.
      cause - the exception thrown by the asynchronously executed task. This argument cannot be null.
      Throws:
      NullPointerException - thrown if the specified cause is null
  • Method Details

    • rethrowCause

      public final RuntimeException rethrowCause()
      Throws the cause of this exception if it is an instance of Error or RuntimeException, or throws a RuntimeException exception with the cause of this exception as the cause of the thrown exception.

      Note that this method never returns normally and always throws an exception. The return value is simply for convenience, so that you can write:

      throw rethrowCause();

      This allows the Java compiler to detect that the code after this method is not reachable.

      Returns:
      this method never returns, the return value is provided solely for convenience
    • rethrowCause

      public final <T extends Throwable> RuntimeException rethrowCause(Class<? extends T> checkedType) throws T
      Throws the cause of this exception if it is an instance of Error or RuntimeException or is of the given type, or throws a RuntimeException exception with the cause of this exception as the cause of the thrown exception.

      Note that this method never returns normally and always throws an exception. The return value is simply for convenience, so that you can write:

      throw rethrowCause(MyException.class);

      This allows the Java compiler to detect that the code after this method is not reachable.

      Type Parameters:
      T - the type of the checked exception type which might be rethrown as is
      Parameters:
      checkedType - a type defining a Throwable, if the cause implements this class, it is simply rethrown instead of wrapped. This argument cannot be null. However, if null is passed for this argument, the cause is still rethrown but a NullPointerException will be attached to it as a suppressed exception.
      Returns:
      this method never returns, the return value is provided solely for convenience
      Throws:
      T - thrown if the given exception is an instance of the given class