I have the code where there can be a division by zero:
Binding binding = new Binding();
GroovyShell shell = new GroovyShell(binding);
conta = shell.evaluate(conta).toString();
txtConta.setText(conta);
Where on the 4th line, the evaluate(conta).toString();
method returns the result of an arithmetic expression in String . However if you have a division by 0, the program closes and launches the ArithmeticException
just on that line. Is there a way for me to check if there is any division by 0 in this snippet and just put a String on the screen as "Error: Divide by 0" without crashing?