Hello,
Everything is in the title.
I don't understand why it's not necessary to throw the ArithmeticException in the divideByZero() method.
Thanks,
Alexandre
Why we shouldn't throw the Exception in the divideByZero() method?
Resolved
Comments (2)
- Popular
- New
- Old
You must be signed in to leave a comment
Lisa
21 February 2022, 10:59solution
The ArithmeticException is an unchecked (runtime) exception. You only have to do exception handling for checked exceptions, ie. use a try-catch block or throw the exception up using the throws keyword in the method definition.
But as you see in the main method, you can catch a runtime exception.
+2
Alexandre Desbois
21 February 2022, 11:11
Oh yes, I already forgot that rule haha.
It's clear now, thanks!
+1