0

Java handling why cant catch error ?

Why can not get error ? We get different error except "Error" public class MyClass { public static void main(String[ ] args) { try { int a= 2; int b = 2; String sum=a+b; // int to String for catch error System.out.println(sum); } catch (Exception e) { System.out.println("Error"); } } }

2nd Jan 2021, 3:26 AM
Sajid Ali
Sajid Ali - avatar
5 Réponses
+ 2
Sajid Ali a and b are integer so sum will be integer too.
2nd Jan 2021, 3:31 AM
A͢J
A͢J - avatar
+ 6
Sajid Ali There is two types of error. Runtime error. Compile Time error. So it is compile time error that's why we don't get catch.
2nd Jan 2021, 3:37 AM
A͢J
A͢J - avatar
+ 3
Try throwing a Zero division error and catching it that will work but in your case your code Is fine so it will run
3rd Jan 2021, 4:16 AM
Programmado
Programmado - avatar
+ 1
Well, Im not going to answer because it has already been, but I noticed you had the Javascript tag, regardless of what people may say or what you may thing, “Java” is NOT the same as “Javascript”, JS is used for web development, and Java is very different. Along with Java having nothing to do with HTML (unless your doing server backend things with java or smth)
2nd Jan 2021, 3:52 PM
Payton Coats
Payton Coats - avatar
0
I knew that,, We learning about handling errors, And i want to knew a reason, why not get error which define by me.
2nd Jan 2021, 3:34 AM
Sajid Ali
Sajid Ali - avatar