[erlang-questions] Division by Zero

Thomas Allen <>
Thu Nov 15 15:03:43 CET 2012


On Thu, Nov 15, 2012 at 03:42:42PM +0200, Lucky Khoza wrote:
> How do i resolve division by zero errors in Erlang.

You can catch errors like this with the try/catch construct, documented
here:

  http://www.erlang.org/doc/reference_manual/expressions.html#id78820

An example for your specific case:

  1> try 1 / 0 catch error:badarith -> io:format("Impossible!~n") end.   
  Impossible!
  ok

Note above that division by zero results in a 'badarith' error, for "bad
arithmetic."

You ought to refer to tutorials and the manual for basic things like these.

Thomas



More information about the erlang-questions mailing list