你可以如何告诉JavaCard中的异常抛出了哪个原因代码?

huangapple go评论70阅读模式
英文:

How can I tell which reason code an exception has thrown in JavaCard?

问题

我正在尝试查找为什么在我的小程序中引发了CryptoException,但我很困惑。

我尝试了这个:

catch (CryptoException e) {
    if (e instanceof CryptoException.ILLEGAL_USE) {
        //发送特定的APDU
    }
}

以及这个:

catch (CryptoException e) {
    if (e == (short)5) {
        //发送特定的APDU
    }
}

还有这个:

catch (CryptoException e) {
    if (e == CryptoException.ILLEGAL_USE) {
        //发送特定的APDU
    }
}

但似乎都不起作用,我找不到使用原因代码来发送特定APDU的正确方法。是否有一种方法可以做到这一点?

英文:

I'm trying to find out why a CryptoException has been thrown in my applet but I'm struggling.

I've tried this:

catch (CryptoException e) {
    if (e instanceof CryptoException.ILLEGAL_USE) {
        //send certain apdu
    }
}

And this:

catch (CryptoException e) {
    if (e == (short)5) {
    //send certain apdu
    }
}

And also this:

catch (CryptoException e) {
    if (e == CryptoException.ILLEGAL_USE) {
    //SEND CERTAIN APDU
    }
}

But none of them seem to work and I can't find the right way to use the reason code to send a specific apdu. Is there a way to do this?

答案1

得分: 1

调用 getReason()CryptoException 上:

try {
    // . . .
} catch (CryptoException e) {
    if (e.getReason() == CryptoException.ILLEGAL_USE) {
        // 发送特定的APDU
    }
}
英文:

Call getReason() on the CryptoException:

try {
    // . . .
} catch (CryptoException e) {
    if (e.getReason() == CryptoException.ILLEGAL_USE) {
        // SEND CERTAIN APDU
    }
}

huangapple
  • 本文由 发表于 2023年7月17日 22:25:38
  • 转载请务必保留本文链接:https://go.coder-hub.com/76705459.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定