[erlang-questions] Exceptions in guards are blocked. Why?

Robert Virding rvirding@REDACTED
Thu Jan 29 15:21:22 CET 2009


In guards it is defined that an exception in the guard means that the guard
fails. It has basically been so since the beginning of (erlang) time.

If you have a guard sequence:

f(...) when <guard1> ; <guard2> ; ... ->

then both failure and an exception in one of the guards means that just that
that guard fails and the next is tested, and the clause may still be chosen.
See http://erlang.org/doc/reference_manual/part_frame.html.

This is one point where using a guard sequence differs from using 'or' or
'orelse'. So, while an exception in one guard above means that the next
guard is tested, an exception in the following:

f(...) when <guard1> orelse <guard2> orelse ... ->

means that the whole guard will fail, and the clause not chosen.

Robert

2009/1/29 Alexander Semenov <bohtvaroh@REDACTED>

> Hi, folks,
>
> Can you explain me why exceptions are blocked in guards?
> For example I wrote this in erlang shell:
>
> F = fun(X) when (X == 0) or (X / 0 > 2) -> true; (_) -> false end.
> F(0).
> false
>
> Is this cause of 'side effects free' guards nature?
> --
> Alexander Semenov <bohtvaroh@REDACTED>
>
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://www.erlang.org/mailman/listinfo/erlang-questions
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20090129/68f3051a/attachment.htm>


More information about the erlang-questions mailing list