Rao*_*722 4 java recursion exception smartcard javacard
虽然Java Card不推荐使用递归编程风格,但我想对Fibonacci算法进行一些测试.我编写了一个函数来计算Fibonacci的大整数套件(由字节数组表示).
我的代码如下:
public static byte[] fibonacci(byte[] n) {
if (isLEThan1(n)) {
return n;
}
else {
return add(fibonacci(subtract(n, new byte[]{0x01})),fibonacci(subtract(n,new byte[]{0x02})));
}
}
Run Code Online (Sandbox Code Playgroud)
如果字节数组表示的整数小于或等于1,则boolean isLEThan(byte[])返回where,true否则返回false.
byte[] add(byte[], byte[])并对byte[] subtract(byte[], byte[])由字节数组表示的大整数实现加法和减法.它们返回一个包含操作结果的新字节数组.
我认为通过给上面描述的函数提供一个大数组,我将得到一个异常,例如SystemException.NO_RESOURCE由于递归调用而减去实例化的数组.
但我必须认为我没有抓住正确的例外,因为我得到6F00了状态字.
这是我考虑的例外列表:
try {
fibonacci(array);
} catch (ArithmeticException e) {
ISOException.throwIt((short) 0x0100);
} catch (ArrayStoreException e) {
ISOException.throwIt((short) 0x0200);
} catch (APDUException e) {
ISOException.throwIt(Util.makeShort((byte) 0x03,
(byte) e.getReason()));
} catch (CryptoException e) {
ISOException.throwIt(Util.makeShort((byte) 0x04,
(byte) e.getReason()));
} catch (ISOException e) {
ISOException.throwIt(Util.makeShort((byte) 0x05,
(byte) e.getReason()));
} catch (PINException e) {
ISOException.throwIt(Util.makeShort((byte) 0x06,
(byte) e.getReason()));
} catch (ServiceException e) {
ISOException.throwIt(Util.makeShort((byte) 0x07,
(byte) e.getReason()));
} catch (SystemException e) {
ISOException.throwIt(Util.makeShort((byte) 0x08,
(byte) e.getReason()));
} catch (TransactionException e) {
ISOException.throwIt(Util.makeShort((byte) 0x09,
(byte) e.getReason()));
} catch (ClassCastException e) {
ISOException.throwIt((short) 0x0A00);
} catch (IndexOutOfBoundsException e) {
ISOException.throwIt((short) 0x0B00);
} catch (NegativeArraySizeException e) {
ISOException.throwIt((short) 0x0C00);
} catch (NullPointerException e) {
ISOException.throwIt((short) 0x0D00);
} catch (SecurityException e) {
ISOException.throwIt((short) 0x0E00);
}
}
Run Code Online (Sandbox Code Playgroud)
那么,在这种情况下,是否有人对有关的例外情况有所了解?
这是一个SystemException.但是,ISO/IEC 7816-4不允许您仅使用任何状态字.而是用例如(short) (0x6700 | 0x0080 | e.getReason())你的理由ISOException.
| 归档时间: |
|
| 查看次数: |
150 次 |
| 最近记录: |