JavacardOS will not accept order any more, please contact our partner Feitian online Store:
https://ftsafe.en.alibaba.com/index.html
https://ftsafe.en.alibaba.com/index.html
How to throw an exception in my applet
Moderator: product
How to throw an exception in my applet
Hi, everyone
I'm learning to write Java Card Applet.
I want to throw an exception when the program execution error occurs, How to write the code in my applet?
Can anyone help me?
I'm learning to write Java Card Applet.
I want to throw an exception when the program execution error occurs, How to write the code in my applet?
Can anyone help me?
Re: How to throw an exception in my applet
There is a special function for exception handling in class "ISOException":
public static void throwIt(short sw)
{}
you could use it.
Firstly, you need to import the class "ISOException" in your Applet by using the command below:
"import javacard.framework.ISOException;"
next step, call the function when you need,such as:
if(condition == false)
{
ISOException.throwIt((short)0x6F00);
}
Hope it helps you.
public static void throwIt(short sw)
{}
you could use it.
Firstly, you need to import the class "ISOException" in your Applet by using the command below:
"import javacard.framework.ISOException;"
next step, call the function when you need,such as:
if(condition == false)
{
ISOException.throwIt((short)0x6F00);
}
Hope it helps you.
-
- Posts: 9
- Joined: Tue Jun 25, 2019 3:19 am
- Points :306
- Contact:
Re: How to throw an exception in my applet
you can throw any short value .mjalali1365 wrote: ↑Wed Jul 17, 2019 2:09 amDoes it only throw 0x6F00? How one can throw the reason for an specific exception?
such as ISOException.throwIt((short)0x6899); or ISOException.throwIt((short)0x2222);
well
-
- Posts: 9
- Joined: Tue Jun 25, 2019 3:19 am
- Points :306
- Contact:
Re: How to throw an exception in my applet
suppose that I do an encryption without first generating the key (run time error), does'nt the function generate an exception to be thrown?kuafu wrote: ↑Wed Jul 17, 2019 4:54 amyou can throw any short value .mjalali1365 wrote: ↑Wed Jul 17, 2019 2:09 amDoes it only throw 0x6F00? How one can throw the reason for an specific exception?
such as ISOException.throwIt((short)0x6899); or ISOException.throwIt((short)0x2222);
Re: How to throw an exception in my applet
Any exception that beyond your code logic will be catched by JAVA virtual machine automatically;mjalali1365 wrote: ↑Wed Jul 17, 2019 6:06 amsuppose that I do an encryption without first generating the key (run time error), does'nt the function generate an exception to be thrown?kuafu wrote: ↑Wed Jul 17, 2019 4:54 amyou can throw any short value .mjalali1365 wrote: ↑Wed Jul 17, 2019 2:09 am
Does it only throw 0x6F00? How one can throw the reason for an specific exception?
such as ISOException.throwIt((short)0x6899); or ISOException.throwIt((short)0x2222);
if you want to do it by yourself, please refer to the following example below:
try
{
int x=d.div(4,0);
System.out.println("x="+x);
}
catch(Exception e)
{
System.out.println("error message");
System.out.println(e.getMessage());
System.out.println(e.toString());
e.printStackTrace();
}
Who is online
Users browsing this forum: No registered users and 26 guests