[erlang-questions] Exceptions in guards are blocked. Why?
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.
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.
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.
> Is this cause of 'side effects free' guards nature?
> Alexander Semenov <bohtvaroh@REDACTED>
> erlang-questions mailing list
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the erlang-questions