Dawn Goxhaj wrote:so I am doing a fraction exception test with a denominator is zero exception. everything compiles except the actual FractionExceptionTest which gives me one error in the catch which is: error: exception DenominatorIsZero is never thrown in body of corresponding try statement
catch(DenominatorIsZero e)
^
1 error
I have found a plethora of reasons for this but am falling victim to information overload and am getting nowhere. Below are all 3 parts of the code. hoping someone can help.
Thanks in advance!!
MJ
Hi Dawn,
I would say try to always simplify your code. So, instead of using all these classes you can just take care of the denominator zero with the exception. Like this
try {
int num1 = 30, num2 = 0;
int output = num1 / num2;
System.out.println("Result = " + output);
} catch (ArithmeticException e) {
System.out.println("[PhoneCoding.com-INFO LOG] Arithmetic Exception: You can't divide an integer by 0");
}
Simple is always better.
--Thiago