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. See
035   * https://github.com/jspecify/jspecify-reference-checker/blob/61aafa4ae52594830cfc2d61c8b113009dbdb045/src/main/java/com/google/jspecify/nullness/NullSpecTransfer.java#L789
036   * and https://github.com/jspecify/jspecify/issues/490.
037   *
038   * (That would also have ensured that its cause was always an Error, rather than possibly another
039   * kind of Throwable that was later passed to initCause. Then we could have declared the override
040   * `public final Error getCause()`.)
041   */
042
043  /**
044   * Creates a new instance with {@code null} as its detail message and no cause.
045   *
046   * @deprecated Prefer {@linkplain ExecutionError(Error)} a constructor that accepts a cause: Users
047   *     of this class typically expect for instances to have a non-null cause. At the moment, you
048   *     can <i>usually</i> still preserve behavior by passing an explicit {@code null} cause. Note,
049   *     however, that passing an explicit {@code null} cause prevents anyone from calling {@link
050   *     #initCause} later, so it is not quite equivalent to using a constructor that omits the
051   *     cause.
052   */
053  @Deprecated
054  protected ExecutionError() {}
055
056  /**
057   * Creates a new instance with the given detail message and no cause.
058   *
059   * @deprecated Prefer {@linkplain ExecutionError(String, Error)} a constructor that accepts a
060   *     cause: Users of this class typically expect for instances to have a non-null cause. At the
061   *     moment, you can <i>usually</i> still preserve behavior by passing an explicit {@code null}
062   *     cause. Note, however, that passing an explicit {@code null} cause prevents anyone from
063   *     calling {@link #initCause} later, so it is not quite equivalent to using a constructor that
064   *     omits the cause.
065   */
066  @Deprecated
067  protected ExecutionError(@CheckForNull String message) {
068    super(message);
069  }
070
071  /**
072   * Creates a new instance with the given detail message and cause. Prefer to provide a
073   * non-nullable {@code cause}, as many users expect to find one.
074   */
075  public ExecutionError(@CheckForNull String message, @CheckForNull Error cause) {
076    super(message, cause);
077  }
078
079  /**
080   * Creates a new instance with {@code null} as its detail message and the given cause. Prefer to
081   * provide a non-nullable {@code cause}, as many users expect to find one.
082   */
083  public ExecutionError(@CheckForNull Error cause) {
084    super(cause);
085  }
086
087  private static final long serialVersionUID = 0;
088}