简体   繁体   中英

Why does changing dispatcher in catch block throw VerifyError

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM