Under the hood, B4X (at least B4J and B4A that I know of), does a float division and then casts the result to an Int. Floating division by 0 does not throw an exception in Java. It results as the largest or smallest possible value for the given type (depending on the positive or negative result of the division). As the link below shows, that's the proper implementation of the IEEE 754 spec (IEEE Standard for Floating-Point Arithmetic)
Why doesn't this code throw an ArithmeticException? Take a look: public class NewClass { public static void main(String[] args) { // TODO code application logic here double tab...
stackoverflow.com
Update: B4i also casts the denominator as a double
BTW, I've just re-installed B4J version 8.50 (that's the oldest one I have a copy of), it it produces the same result. For some reason, I thought I had B4J bomb out on division by 0, since I would use that to, on purpose, create a program fault. I guess I'm remembering wrong.
I am remembering wrong. I just looked at that project and noticed that division by 0 did NOT work (it did not bomb the program), so I resorted to defining a list and adding an element BEFORE initializing the list. I guess I just never gave it a second thought that division by 0 did not bomb.
I was a bit surprised too when I discovered that B4J followed Java via a scenic route when dividing integers. Was no worries though, because with production code I never rarely do a division without checking for zero first anyway. ?
But I admit that I may have had some longer-than-necessary debugging sessions with private code. ?