Quick revision
The short answer
When the task inside runAsync throws, CompletableFuture catches the exception and stores it in the returned future, which completes exceptionally. Nothing logs it, and because the service throws the future away, nobody ever looks, so the failures are invisible. The fix is to observe the future with whenComplete or exceptionally, or to handle errors inside the task, to count failures as a metric, and to ask whether audit events need durable delivery with retries instead of fire-and-forget.
What to remember
In this answer, we saw that runAsync catches exceptions from its task and stores them in the returned future, so when the service discards that future, nobody observes the failure and nothing is logged. Attaching whenComplete or exceptionally, or handling errors inside the task, makes failures visible, and a metric for failures makes them alertable. For audit events, which must not be lost, durable delivery such as a transactional outbox with retries is better than fire-and-forget.
Your turn
Answer it aloud as you would in the interview, or type your answer below. Then show one part at a time and compare.
When the task inside runAsync throws, CompletableFuture catches the exception and stores it in the returned future, which completes exceptionally. Nothing logs it, and because the service throws the future away, nobody ever looks, so the failures are invisible. The fix is to observe the future with whenComplete or exceptionally, or to handle errors inside the task, to count failures as a metric, and to ask whether audit events need durable delivery with retries instead of fire-and-forget.
Why this question is asked
Missing data with no errors in the logs is one of the most unsettling bugs in production, because it means our monitoring cannot see the failure at all. Fire-and-forget calls with CompletableFuture are a classic source of it. Interviewers ask this question to see whether we know where exceptions go in async code and whether we think about delivery guarantees for important data. In this answer, we will reproduce the silent failure, see exactly where the exception goes, make failures visible, and then ask whether audit events should be fire-and-forget at all.
1Reproducing the Silent Failure
Here is the code from the question, with an audit client that sometimes fails, for example because its HTTP call times out.
Notice that nothing appears in the logs. We might expect at least a stack trace on standard error, as we get when a plain Thread dies with an exception, but there is none.
2Where the Exception Goes
runAsync wraps our Runnable in a small task and submits it to an executor, here ForkJoinPool.commonPool() because we passed none. That task calls our Runnable inside a try block that catches every Throwable. If our code throws, the task does not let the exception escape to the thread. Instead it completes the returned CompletableFuture exceptionally, storing the exception inside it.
The reason is the design of CompletableFuture: a failure is a result, just like a value, and it is delivered to whoever observes the future, through join(), get() or a handler. The thread's uncaught exception handler, which normally prints the stack trace, never runs because the exception never reaches it. So the exception sits in the future, and when the future becomes garbage, the exception disappears with it.
6 messages in order. Play them, or step through them one at a time.
The failure is stored in a future that no one ever looks at.
3Making Failures Visible
The minimum fix is to observe the future. A whenComplete handler runs on both outcomes and lets us log the failure with its real cause. We also count failures, because a log line per failure is easy to miss, while a metric can drive an alert.
Notice two other changes. We unwrap the CompletionException so the log shows the real cause, and we pass a dedicated auditExecutor, because a blocking HTTP call should not run on the common pool. Handling the error inside the task with try and catch works too, and is sometimes clearer; what matters is that every failure ends up somewhere we will see it.
4Should Audit Events Be Fire-and-Forget at All?
Logging the failure tells us an event was lost, but it is still lost. For many kinds of data that is acceptable: a click metric or a cache warm-up can be dropped. Audit events usually cannot. They exist to prove later who did what, and a gap in them can be a compliance problem.
For data that must not be lost, we need durable delivery with retries. A common pattern is the transactional outbox: in the same database transaction that saves the order, we insert the audit event into an outbox table. A separate process reads the outbox and sends the events to the audit service, retrying until it succeeds and marking each row as sent. Because the event is committed together with the order, it can no longer be lost between the two, and a temporary outage of the audit service only delays delivery.
So the choice depends on what the data is worth. Fire-and-forget with logging and a metric is fine for best-effort data. For audit, durable delivery is the honest design.
5Follow-up questions
Why does a plain Thread print the stack trace but runAsync does not?
A plain Thread that ends with an exception hands it to its uncaught exception handler, which prints it by default. The task created by runAsync catches every Throwable and stores it in the future, so the exception never escapes the thread and the handler never runs.
Would using a custom executor change this?
No. The catching happens inside the CompletableFuture task, not in the executor. Even with an executor whose threads have an uncaught exception handler, the exception is stored in the future and not seen by the handler. A custom executor is still a good idea for blocking calls, just not for this reason.
Is there a way to find futures that are never observed?
There is no built-in detection in the JDK. Code review and static analysis rules that flag ignored return values of runAsync and supplyAsync are the practical tools, together with team conventions that every future is either returned or ends with a handler.
6Conclusion
In this answer, we saw that runAsync catches exceptions from its task and stores them in the returned future, so when the service discards that future, nobody observes the failure and nothing is logged. Attaching whenComplete or exceptionally, or handling errors inside the task, makes failures visible, and a metric for failures makes them alertable. For audit events, which must not be lost, durable delivery such as a transactional outbox with retries is better than fire-and-forget.
Open with
The events are lost silently because of where the exception goes. runAsync runs the Runnable inside a task that catches every Throwable and completes the returned future exceptionally, storing the exception in it.
Then, if they want more
That is by design: in CompletableFuture a failure is a result, delivered to whoever observes the future. But this code throws the future away, so nobody ever calls join or attaches a handler, and the exception simply disappears with the future. The thread's uncaught exception handler never sees it, which is why there is not even a stack trace.
To fix it, I would first make failures visible: attach whenComplete that unwraps the CompletionException, logs the real cause with the event id, and increments a failure counter so we can alert on it. I would also run the call on a dedicated executor, not the common pool, since it is blocking I/O.
But then I would ask whether audit events should be fire-and-forget at all. Audit data usually must not be lost, so I would use durable delivery, for example a transactional outbox: write the event in the same transaction as the order and have a relay send it with retries, accepting at-least-once delivery and deduplicating by event id.
About this answer
- Last updated
- 12 November 2026
- Checked
- Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
- Where the question comes from
- Written by Scrivio for practice. It is not taken from an interview.
- Official documentation
- java.util.concurrent, package documentation, JLS chapter 17, Threads and Locks
Report an issue with this answer
Copy the line below and send it to the author with what you found. It carries the address of this page.
Issue with "A service calls CompletableFuture.runAsync(() -> auditClient.send(event)) and never uses...": https://scrivio-interview-library.netlify.app/java/completable-future/a822b22aad/