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"); } } }
5 odpowiedzi
+ 2
Sajid Ali
a and b are integer so sum will be integer too.
+ 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.
+ 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
+ 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)
0
I knew that,,
We learning about handling errors,
And i want to knew a reason, why not get error which define by me.