causedCancellationException

fun Throwable.causedCancellationException(): CancellationException?

Traverses this throwable's cause chain to find a CancellationException.

It walks through this and its causes until the first CancellationException is encountered, and returns that exception. If no CancellationException is found in the chain, returns null.

This is useful when you need to distinguish cancellations from other failures while handling errors.

Receiver

the root Throwable to inspect

Return

the first CancellationException found in the cause chain, or null if none present