001/*
002 * Copyright (C) 2011 The Guava Authors
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
005 * in compliance with the License. You may obtain a copy of the License at
006 *
007 * http://www.apache.org/licenses/LICENSE-2.0
008 *
009 * Unless required by applicable law or agreed to in writing, software distributed under the License
010 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
011 * or implied. See the License for the specific language governing permissions and limitations under
012 * the License.
013 */
014
015package com.google.common.util.concurrent;
016
017import com.google.common.annotations.GwtCompatible;
018import javax.annotation.CheckForNull;
019
020/**
021 * {@link Error} variant of {@link java.util.concurrent.ExecutionException}. As with {@code
022 * ExecutionException}, the error's {@linkplain #getCause() cause} comes from a failed task,
023 * possibly run in another thread. That cause should itself be an {@code Error}; if not, use {@code
024 * ExecutionException} or {@link UncheckedExecutionException}. This allows the client code to
025 * continue to distinguish between exceptions and errors, even when they come from other threads.
026 *
027 * @author Chris Povirk
028 * @since 10.0
029 */
030@GwtCompatible
031@ElementTypesAreNonnullByDefault
032public class ExecutionError extends Error {
033  /*
034   * Ideally, this class would have exposed only constructors that require a non-null cause. We
035   * might try to move in that direction, but there are complications. See
036   * https://github.com/jspecify/nullness-checker-for-checker-framework/blob/61aafa4ae52594830cfc2d61c8b113009dbdb045/src/main/java/com/google/jspecify/nullness/NullSpecTransfer.java#L789
037   */
038
039  /** Creates a new instance with {@code null} as its detail message. */
040  protected ExecutionError() {}
041
042  /** Creates a new instance with the given detail message. */
043  protected ExecutionError(@CheckForNull String message) {
044    super(message);
045  }
046
047  /** Creates a new instance with the given detail message and cause. */
048  public ExecutionError(@CheckForNull String message, @CheckForNull Error cause) {
049    super(message, cause);
050  }
051
052  /** Creates a new instance with the given cause. */
053  public ExecutionError(@CheckForNull Error cause) {
054    super(cause);
055  }
056
057  private static final long serialVersionUID = 0;
058}