Landerl Young
03/06/2019, 9:16 AMobject CoroutineCrashTest {
private val scope = GlobalScope + Job()
fun run() = scope.launch(Dispatchers.Default) {
doAwaitInside()
}
private suspend fun doAwaitInside() {
try {
testAsync().await()
} catch (e: IllegalStateException) {
// catched but still crash
}
}
private fun testAsync() = scope.async(Dispatchers.Default) {
throw IllegalStateException("test")
}
}
When run() is executed, the IllegalStateException will go beyond doAsyncInside and finally be handled by the Thread.unchaughtExceptionHandler. On Android the app crashes, on JVM the console logs the exception.
However if i change the scope declare to
val scope = GlobalScope
Everything works fine, just as expected. Which is really spooky.🤣
BTW:
my kotlin version is 1.3.11
my coroutine version is 1.1.0