I developed an applet in Java Card and it works fine. Now I am working on the sturdiness of this applet and more precisely, what happens if the card is deplugged during the applet execution for example.
I am wondering if there is an Exception which handle this kind of things ?
I am searching for something like :
try {
...
}
// If the card is disconnected while the applet execution
catch (Exception e) {
...
}
Thank you in advance.
As the smart cards haven't any battery inside, you can't have any try ... catch ...
like this. Alternatively you can take advantages of Transactions
. The Transaction APIs are provided just for your goal. The operations that are between beginTransation()
and commitTransation()
methods, apply only if the commitTransation()
complete successfully. And if any exeption/card tear or card reset happens before commitTransation()
, everything returns to its original state (ie to the state that it has before beginTransaction()
)
It is like this :
.
.
JCSystem.beginTransaction();
//put your critical code here.
JCSystem.commitTransaction();
.
.
You can also use JCSystem.commitTransaction();
to terminate a transaction in a specific situation as follow :
.
.
JCSystem.beginTransaction();
//put your critical code here.
if (condition) {
JCSystem.commitTransaction();
}
JCSystem.commitTransaction();
.
.
Note that:
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.