Abhishek Bansal
06/25/2024, 12:39 PMrunBlocking {
try {
val response = withTimeout(timeout) {
// okhttp network call
}
// do something with Response
} catch (e: TimeoutCancellationException) {
// log exception
} catch(e: Exception) {
// log exception
}
}
I am getting bunch of Parent job is cancelling exceptions in last catch block. This is not something that is locally reproducible but observed in data. what might be the possible reasons for this?CLOVIS
06/25/2024, 12:45 PMCancellationException , which you shouldn't do.
Instead, you can write
} catch (e: TimeoutCancellationException) {
// log exception
} catch(e: Exception) {
coroutineContext.ensureActive()
// log exception
}Abhishek Bansal
06/25/2024, 12:48 PMParent job is cancelling message here?CLOVIS
06/25/2024, 12:49 PMAbhishek Bansal
06/25/2024, 12:58 PMTimeoutCancellationException or if its a CancellationException then Job was cancelled should be the message.
Parent here is runBlocking , I am looking for possible reasons for which parent is getting cancelled before child.
Could it be due to some unhandled exception in // do something with Response block?CLOVIS
06/25/2024, 1:00 PMcancel or by throwing an exception in another coroutine that is a child of the same Job (here, `runBlocking`'s)