3 ms·
In most languages you get an exception
by smabie 6y ago
In most languages you get an exception
- yakubin 6y agoWhich languages would those be?
- smabie 6y agoI guess I'm thinking of Python mostly. I thought OCaml did as well but apparently not.
- warkdarrior 6y ago$ python3 Python 3.9.1 (default, Feb 3 2021, 07:04:15) [Clang 12.0.0 (clang-1200.0.32.29)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> 10 / 0 Traceback (most recent call last): File "<stdin>", line 1, in <module> ZeroDivisionError: division by zero >>>
- yakubin 6y agoAlthough Python seems to be the exception to the rule here, your example isn't exactly right. In your example, you're performing integer division, not floating point division. In most languages, integer division by zero is indeed some kind of exception (or UB, which will most likely result in a hardware exception, causing a signal sent to the process). However, floating point division by zero is well-defined, as per definition of floating point arithmetic (in some RFCs), and most languages don't throw exceptions in this case. Python indeed seems to be the exception to the rule.