Alex Styl
11/07/2022, 8:29 AMerror()
doesn’t crash the app? Given there is no supervisor job I was expecting this to crash the program but it doesn’t.
I can see the ‘Starting’ the crash and then ‘job done’ in the logs 🤔
suspend fun main() {
val scope = CoroutineScope(Dispatchers.Main.immediate)
debugLn { "Starting" }
scope.launch {
error("CRASH!")
}
delay(500)
debugLn { "Job done" }
}
Sam
11/07/2022, 8:43 AMscope
that you created that would tell the app to crash when one of its jobs fails. What you really want is something more like this:
suspend fun main() = coroutineScope {
debugLn { "Starting" }
launch {
error("CRASH!")
}
delay(500)
debugLn { "Job done" }
}
Sam
11/07/2022, 8:49 AMcoroutineScope
builder creates a scope and then waits for all of its children to complete. That’s what causes it to throw an exception to the containing function if one of its child jobs fails.streetsofboston
11/07/2022, 12:31 PM