Closed tajmone closed 5 years ago
This is definitely a bug. I'll add an interpreter check for this so that the author can add that check.
Although Alan as a language tries to prevent run-time errors, there are a few for which there seems to be no good way to handle. The preferable solution would be to have the interpreter say something like "You can't do divisions by zero", but since there is no way to know if the player even is to know about the math going on, I think an "Application Error" would be appropriate.
I also think that the producing an Application Error is better, for it would emphasize the need on the author side to better check the code (otherwise, if the game just carried on, it would be soon forgotten and the player wouldn't make a report about this).
Thanks for a excellent problem report that became the test case straight off!
I was testing an adventure that implements verbs to carry out the four basic operations of arithmetic and noticed that divide by zero crashes all the interpreters.
Possibly it's a bug, for there should be some failsafe mechanism to prevent similar illegal operations — after all, this was a legit example where the context could provide such cases.
Here's the code:
Tested with the following command:
Which caused all three terps to crash (WinArun, Gargoyle and ARun). Arun would show the response up to "Sure, 4 divided by 0 equals" before crashing.
Of course, the easy fix was adding the following Check:
But having the interpreter check for a division by zero would be better — at least it should exit with an error, instead of just crashing silently, so that the error message could help the author trace the error and its nature.