How can I give the exception method if I entered a string value for a integer value? I mean the user asking to enter a integer value. But user entered a string value. How should I catch this error using exception? Can you give some examples?
Printable View
How can I give the exception method if I entered a string value for a integer value? I mean the user asking to enter a integer value. But user entered a string value. How should I catch this error using exception? Can you give some examples?
Hi
Use Integer.parseInt(String obj) method.
If it gives exception in parsing,then u can catch it and give a message to the user about invalid data..
for example:
if user entered is "hello" instead of 56.
String val="hello".
int i=Integer.parseInt(val);
Regards,
Raghu