coder82
08/21/2019, 12:26 PMkingsley
08/21/2019, 3:00 PMcancel
always cancels the job with a cancellation exception. The coroutine will only fail if it were to throw an exception within itself other than a cancellation exception
the documentation says it should fail the coroutineHmm… I found this
If the cause of cancellation is a different exception, then the job is considered to have failedbut it also says
This usually happens when the code of the job encounters some problem and throws an exception.Looking at the code for cancel(Throwable) which is now deprecated, I found this:
This method has bad semantics when cause is not a [CancellationException]So, either you use a
cancel(CancellationException)
or a cancel(message: String, cause: Throwable)
which gets wrapped in a CancellationException. There’s really no way to fail the coroutine from outside AFAIK