How to handle divide by zero in a language that doesn't support exceptions?
I'm in the middle of developing a new programming language to solve some
business requirements, and this language is targeted at novice users. So
there is no support for exception handling in the language, and I wouldn't
expect them to use it even if I added it.
I've reached the point where I have to implement the divide operator, and
I'm wondering how to best handle a divide by zero error?
I seem to have only three possible ways to handle this case.
Ignore the error and produce 0 as the result. Logging a warning if possible.
Add NaN as a possible value for numbers, but that raises questions about
how to handle NaN values in other areas of the language.
Terminate the execution of the program and report to the user a severe
error occurred.
Option #1 seems the only reasonable solution. Option #3 is not practical
as this language will be used to run logic as a nightly cron.
What are my alternatives to handling a divide by zero error, and what are
the risks with going with option #1.
No comments:
Post a Comment