1
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 in the 4th line, the method evaluate(conta).toString();
returns the result of an arithmetic expression in String. But if you have any division by 0, the program closes and launches the ArithmeticException
just on that same line. Is there any way I can verify if there is any division by 0 in this section and just print on the screen a String as "Error: Split by 0" without crashing program ?
You can put the code inside a Try Catch block and catch when you give the Exception you launch the message treating it, Stating that there was a split by 0
– Edenilson Bila
To help: https://stackoverflow.com/a/1657925/6510304
– Don't Panic
Related: Treat Arithmeticexception in another method
– user28595
Remember that this Groovyshell is a "third party" API. It returns some errors in its own classes, but the Exception released by it is the same Arithmeticexception, returning the 4th line of the example.
– Daniel Santos