0

How to create an Exception of Number format exception

Exception handling

23rd May 2021, 1:12 PM
Bataung Arnold Khotso Pitso
6 Antworten
+ 2
🅰🅹 🅐🅝🅐🅝🅣 Can this be a example? public class Program { public static void main(String[] args) { int a=63; System. out. print(a/0); } }
23rd May 2021, 2:36 PM
Atul [Inactive]
+ 2
Okay so I have to treat number and arithmetic exception differently?
23rd May 2021, 2:59 PM
Atul [Inactive]
+ 1
‏‪‏‪‏‪‏‪Arnold Pitso Just try to convert string to integer. You will get that exception. Just do this String name = "AJ"; int n = Integer.parseInt(name);
23rd May 2021, 1:22 PM
A͢J
A͢J - avatar
+ 1
Atul it is an ArithmeticException not NumberFormatException.
23rd May 2021, 2:40 PM
Chinmaya Moorthy S
Chinmaya Moorthy S - avatar
+ 1
Atul That's ArithmeticExcpetion - when you divide any number with 0 NumberFormatException - When you try to convert a non numeric value to numberic. but String name = "12345"; will not give exception.
23rd May 2021, 2:49 PM
A͢J
A͢J - avatar
0
Atul Yes
23rd May 2021, 3:00 PM
A͢J
A͢J - avatar