• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2011 The Guava Authors
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
5  * in compliance with the License. You may obtain a copy of the License at
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software distributed under the License
10  * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
11  * or implied. See the License for the specific language governing permissions and limitations under
12  * the License.
13  */
14 
15 package com.google.common.util.concurrent;
16 
17 import com.google.common.annotations.GwtCompatible;
18 import javax.annotation.CheckForNull;
19 
20 /**
21  * Unchecked variant of {@link java.util.concurrent.ExecutionException}. As with {@code
22  * ExecutionException}, the exception's {@linkplain #getCause() cause} comes from a failed task,
23  * possibly run in another thread.
24  *
25  * <p>{@code UncheckedExecutionException} is intended as an alternative to {@code
26  * ExecutionException} when the exception thrown by a task is an unchecked exception. However, it
27  * may also wrap a checked exception in some cases.
28  *
29  * <p>When wrapping an {@code Error} from another thread, prefer {@link ExecutionError}. When
30  * wrapping a checked exception, prefer {@code ExecutionException}.
31  *
32  * @author Charles Fry
33  * @since 10.0
34  */
35 @GwtCompatible
36 @ElementTypesAreNonnullByDefault
37 public class UncheckedExecutionException extends RuntimeException {
38   /*
39    * Ideally, this class would have exposed only constructors that require a non-null cause. We
40    * might try to move in that direction, but there are complications. See
41    * https://github.com/jspecify/jspecify-reference-checker/blob/61aafa4ae52594830cfc2d61c8b113009dbdb045/src/main/java/com/google/jspecify/nullness/NullSpecTransfer.java#L789
42    */
43 
44   /** Creates a new instance with {@code null} as its detail message. */
UncheckedExecutionException()45   protected UncheckedExecutionException() {}
46 
47   /** Creates a new instance with the given detail message. */
UncheckedExecutionException(@heckForNull String message)48   protected UncheckedExecutionException(@CheckForNull String message) {
49     super(message);
50   }
51 
52   /** Creates a new instance with the given detail message and cause. */
UncheckedExecutionException(@heckForNull String message, @CheckForNull Throwable cause)53   public UncheckedExecutionException(@CheckForNull String message, @CheckForNull Throwable cause) {
54     super(message, cause);
55   }
56 
57   /** Creates a new instance with the given cause. */
UncheckedExecutionException(@heckForNull Throwable cause)58   public UncheckedExecutionException(@CheckForNull Throwable cause) {
59     super(cause);
60   }
61 
62   private static final long serialVersionUID = 0;
63 }
64