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"); } } }

29th Nov 2017, 12:16 AM
Rizan
Rizan - avatar
5 Réponses
+ 3
@Boris He did it on purpose so he could test out exception catching.
29th Nov 2017, 12:27 AM
AgentSmith
+ 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"); } } }
29th Nov 2017, 12:24 AM
AgentSmith
+ 2
You can't print the result of 2 / 0, because of the / by zero exception.
29th Nov 2017, 12:26 AM
Boris Batinkov
Boris Batinkov - avatar
+ 1
Oh! Thanks!
29th Nov 2017, 12:25 AM
Rizan
Rizan - avatar
0
I wasn't trying to. I was simply trying to print some letter e if an error occured...
29th Nov 2017, 12:28 AM
Rizan
Rizan - avatar