0
I was trying to use Try... Catch Exception. What did I miss?
public class catchDivideByInfException { public static void main(String[] args) { int a = 2; int b = 0; try { int c = a / b; System.out.println(c); } Catch (Exception e) { System.out.println("e"); } } }
5 Antworten
+ 3
@Boris He did it on purpose so he could test out exception catching.
+ 2
You accidentally capitalized Catch. ;)
https://code.sololearn.com/cOpViB30Zg15/#java
public class catchDivideByInfException
{
public static void main(String[] args) {
int a = 2;
int b = 0;
try {
int c = a / b;
System.out.println(c);
}
catch (Exception e) {
System.out.println("e");
}
}
}
+ 2
You can't print the result of 2 / 0, because of the / by zero exception.
+ 1
Oh! Thanks!
0
I wasn't trying to. I was simply trying to print some letter e if an error occured...