[erlang-questions] Division by Zero

Richard O'Keefe ok@REDACTED
Thu Nov 15 23:16:27 CET 2012

On 16/11/2012, at 2:42 AM, Lucky Khoza wrote:

> Hi Erlang Developers,
> How do i resolve division by zero errors in Erlang.

Could you please tell us what you actually mean?
For example, I "resolve" division by zero errors in C
by making sure they simply never happen in the first place.
Come to think of it, that's how I "resolve" division by
zero errors in Java, Smalltalk, Lisp, Fortran, AWK,
Python, and Erlang as well.

Some errors are symptoms of bad programming and just plain
_shouldn't_ be caught by handlers in your code lest you
hide mistakes.  Part of Erlang design philosophy is that
it is much better for a process to crash promptly than to
keep on going with imaginary or otherwise incorrect data.

If your question is "given that a division by zero has
NOT been prevented, and has occurred, how do I catch it
and how do I tell that a division by zero is the thing
that happened?"

So have you read chapter 10 of the Erlang reference manual?
This lists the predefined exit reasons in table 10.2 with
their causes.  It says in section 10.3 how to handle such

But I repeat: it is better to *prevent* errors rather than
catch them, if an error that you *could* have prevented is
caught, you will probably regret it, and you should never
handle an exception unless you really can honestly recover
*fully* and continue sanely.

More information about the erlang-questions mailing list