2
I have to do a treatment for possible exceptions within a calculator, one of them would be the division by 0, in the case "Arithmeticexception", but I’m not able to make it work, even after implementing the try-catch
the code continues to return the default message and not the message I wrote on catch
for that mistake:
case 4:
if (num1 < num2){
System.out.println("Impossivel realizar calculo!! \n");
}
else
{
int divide = num1 / num2;
System.out.println("A divisao e: "+divide);
}
try{
int divide = num1 / num2;
System.out.println("A divisao e: "+divide);
} catch(ArithmeticException e){
System.out.println("Erro: divisão por zero!");
}
break;