Unlike Java 9 and later, Java 8 does not provide a static factory method for this scenario. The default constructor can be used instead:
CompletableFuture<T> future = new CompletableFuture<>();
future.completeExceptionally(exception);
More Related Contents:
- Analyze the following code, which exception does it display? (Exception handling, java)
- Why exception occurs in this program?
- Handling InterruptedException in Java
- When to catch java.lang.Error?
- Is it a bad practice to catch Throwable?
- Java 8: Lambda-Streams, Filter by Method with Exception
- Why is the Catch(Exception) almost always a bad Idea?
- How do you implement a re-try-catch?
- Convert from List to CompletableFuture
- Increasing heap space in Eclipse: (java.lang.OutOfMemoryError)
- In which thread do CompletableFuture’s completion handlers execute?
- How do I fix a compilation error for unhandled exception on call to Thread.sleep()?
- try with resources introduce unreachable bytecode
- How to loop user input until an integer is inputted?
- Java: Global Exception Handler
- Throws or try-catch
- What is a suppressed exception?
- Java uncaught global exception handler
- What is the advantage of chained exceptions
- What are reasons for Exceptions not to be compatible with throws clauses?
- Why is “throws Exception” necessary when calling a function?
- Guidelines on Exception propagation (in Java)
- Who is calling the Java Thread interrupt() method if I’m not?
- In Java how can I validate a thrown exception with JUnit?
- Is it okay to throw NullPointerException programmatically? [closed]
- CompletableFuture / ForkJoinPool Set Class Loader
- Why is CompletableFuture.supplyAsync succeeding a random number of times?
- Will a chain of method calls (CompletableFuture API) execute asynchronously if the first method in a chain is asynchronous?
- Java 8 Supplier Exception handling with CompletableFuture
- How to interrupt underlying execution of CompletableFuture