为什么我不能在我的小程序的处理方法中抛出异常?



下面您看到一个程序,它在SELECT APDU命令之后接收任何命令时抛出异常:

public class MyApp extends Applet  {

    private MyApp() {
    }
    public static void install(byte bArray[], short bOffset, byte bLength)
            throws ISOException {
        new MyApp().register();
    }
    public void process(APDU arg0) throws ISOException {
        if (selectingApplet()){
            return;
        }
        ISOException.throwIt((short) 0x0002);
    }
}

问题是:为什么任何APDU命令(SELECT APDU命令除外)的传输都会失败?

OSC: opensc-tool -s 00a404000b0102030405060708090002 -s 0000000
Using reader with a card: ACS CCID USB Reader 0
Sending: 00 A4 04 00 0B 01 02 03 04 05 06 07 08 09 00 02
Received (SW1=0x90, SW2=0x00)
Sending: 00 00 00 00
APDU transmit failed: Transmit failed

是否限制在流程方法主体中使用异常?

没有,但您的问题可能是使用了状态词。您应该遵守ISO 7816-4定义的状态词。试试6xxx范围内的一些。对于T=0和T=1,您可能会有不同的响应。

异常状态字必须符合7816规范。如ISOException.sthrowIt(ISO7816.SW_INS_NOT_SUPPORTED);

也许你的程序需要写:

公共无效程序{

    if (selectingApplet())
    {
        return;
    }
    byte[] buf = apdu.getBuffer();
    switch (buf[ISO7816.OFFSET_INS])
    {
    case (byte)0x00:
        //......
        break;
    default:
        ISOException.throwIt(ISO7816.SW_INS_NOT_SUPPORTED);
    }
}

最新更新