I want to understand why this exception is thrown when I use withContext()
with Dispatchers.Main
or Dispatchers.IO
in catch block.
Here's my code:
init {
viewModelScope.launch {
try {
throw RuntimeException("whatever")
} catch (e: Exception){
withContext(Dispatchers.MAIN) {
e.printStackTrace()
}
}
}
}
This code throws java.lang.VerifyError
Verifier rejected class xx.xxxx.ErrorViewModel: java.lang.Object
xx.xxxx.ErrorViewModel$1.invokeSuspend(java.lang.Object)
failed to verify: java.lang.Object
xx.xxxx.ErrorViewModel$1.invokeSuspend(java.lang.Object):
[0x3D] register v4 has type Reference: java.lang.Exception but expected
Precise Reference: kotlin.jvm.internal.Ref$ObjectRef
(declaration of 'xx.xxxx.ErrorViewModel$1' appears in
/data/app/xx.xxxx-9pkI5L5NB9qa1CWUxAapUw==/base.apk!classes2.dex)
You should never see a VerifyError; this probably indicates a bug in the compiler.
I'd suggest raising an issue on the JetBrains YouTrack site.