Guide to CompletionException in Java
You can read this article with in-browser code execution of sample programs here.
If you are interviewing check out our comprehensive preparation course Java Mulithreading for Engineering Interviews.
Don’t forget to buy your copy of Java Concurrency in Practice. Kindly, consider supporting us on Medium .
Overview
The CompletionException
extends from the RuntimeException
and is thrown when a task hits an error or exception when executing.
The CompletionException
and the ExecutionException
might seem similar but there’s a fundamental difference between the two. The ExecutionException
is thrown only when an attempt is made to retrieve the result/outcome of a task, while the CompletionException
can be thrown when waiting on a task to complete or when trying to retrieve a result computed by a task. In a sense CompletionException
can be thought of as broader in scope than ExecutionException
.
If you are interviewing, consider buying our number#1 course for Java Multithreading Interviews.