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 com.google.common.annotations.GwtIncompatible; 019import com.google.common.annotations.J2ktIncompatible; 020import org.jspecify.annotations.Nullable; 021 022/** 023 * {@link Error} variant of {@link java.util.concurrent.ExecutionException}. As with {@code 024 * ExecutionException}, the error's {@linkplain #getCause() cause} comes from a failed task, 025 * possibly run in another thread. That cause should itself be an {@code Error}; if not, use {@code 026 * ExecutionException} or {@link UncheckedExecutionException}. This allows the client code to 027 * continue to distinguish between exceptions and errors, even when they come from other threads. 028 * 029 * @author Chris Povirk 030 * @since 10.0 031 */ 032@GwtCompatible 033public class ExecutionError extends Error { 034 /* 035 * Ideally, this class would have exposed only constructors that require a non-null cause. See 036 * https://github.com/jspecify/jspecify-reference-checker/blob/61aafa4ae52594830cfc2d61c8b113009dbdb045/src/main/java/com/google/jspecify/nullness/NullSpecTransfer.java#L789 037 * and https://github.com/jspecify/jspecify/issues/490. 038 * 039 * (That would also have ensured that its cause was always an Error, rather than possibly another 040 * kind of Throwable that was later passed to initCause. Then we could have declared the override 041 * `public final Error getCause()`.) 042 */ 043 044 /** 045 * Creates a new instance with {@code null} as its detail message and no cause. 046 * 047 * @deprecated Prefer {@linkplain ExecutionError(Error)} a constructor that accepts a cause: Users 048 * of this class typically expect for instances to have a non-null cause. At the moment, you 049 * can <i>usually</i> still preserve behavior by passing an explicit {@code null} cause. Note, 050 * however, that passing an explicit {@code null} cause prevents anyone from calling {@link 051 * #initCause} later, so it is not quite equivalent to using a constructor that omits the 052 * cause. 053 */ 054 @Deprecated 055 protected ExecutionError() {} 056 057 /** 058 * Creates a new instance with the given detail message and no cause. 059 * 060 * @deprecated Prefer {@linkplain ExecutionError(String, Error)} a constructor that accepts a 061 * cause: Users of this class typically expect for instances to have a non-null cause. At the 062 * moment, you can <i>usually</i> still preserve behavior by passing an explicit {@code null} 063 * cause. Note, however, that passing an explicit {@code null} cause prevents anyone from 064 * calling {@link #initCause} later, so it is not quite equivalent to using a constructor that 065 * omits the cause. 066 */ 067 @SuppressWarnings("InlineMeSuggester") // b/387265535 068 @Deprecated 069 protected ExecutionError(@Nullable String message) { 070 super(message); 071 } 072 073 /** 074 * Creates a new instance with the given detail message and cause. Prefer to provide a 075 * non-nullable {@code cause}, as many users expect to find one. 076 */ 077 public ExecutionError(@Nullable String message, @Nullable Error cause) { 078 super(message, cause); 079 } 080 081 /** 082 * Creates a new instance with {@code null} as its detail message and the given cause. Prefer to 083 * provide a non-nullable {@code cause}, as many users expect to find one. 084 */ 085 public ExecutionError(@Nullable Error cause) { 086 super(cause); 087 } 088 089 @GwtIncompatible @J2ktIncompatible private static final long serialVersionUID = 0; 090}