【问题标题】:Why does changing dispatcher in catch block throw VerifyError为什么在 catch 块中更改调度程序会抛出 VerifyError
【发布时间】:2020-11-24 07:20:48
【问题描述】:

我想了解为什么在 catch 块中使用 withContext()Dispatchers.MainDispatchers.IO 时会引发此异常。

这是我的代码:

init {

    viewModelScope.launch {
        try {
            throw RuntimeException("whatever")
        } catch (e: Exception){
            withContext(Dispatchers.MAIN) {
                e.printStackTrace()
            }
        }
    }
}

此代码抛出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)

【问题讨论】:

    标签: kotlin kotlin-coroutines verifyerror


    【解决方案1】:

    你不应该看到VerifyError;这可能表明编译器中存在错误。

    我建议在 JetBrains YouTrack 网站上提出问题。

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-09-28
    • 1970-01-01
    • 2023-04-01
    • 2011-06-21
    • 2017-02-10
    相关资源
    最近更新 更多