Exceptional v1.2.0 Exceptional.Control

Exception control flow

Summary

Macros

Branch on if the value is an Exception, applying the associated function for that case. Does not catch thrown exceptions

Alias for Exceptional.Control.branch

Macros

branch(maybe_exception, list)

Branch on if the value is an Exception, applying the associated function for that case. Does not catch thrown exceptions.

Examples

iex> use Exceptional.Control
...> branch 1,
...>   value_do: fn v -> v + 1 end.(),
...>   exception_do: fn ex -> ex end.()
2

iex> use Exceptional.Control
...> branch ArgumentError.exception("error message"),
...>   value_do: fn v -> v end.(),
...>   exception_do: fn %{message: msg} -> msg end.()
"error message"

iex> use Exceptional.Control
...> branch Enum.fetch!([], 99),
...>   value_do: fn v -> v + 1 end.(),
...>   exception_do: fn ex -> ex end.()
** (Enum.OutOfBoundsError) out of bounds error
if_exception(maybe_exception, list)

Alias for Exceptional.Control.branch

Examples

iex> use Exceptional.Control
...> if_exception 1, do: fn ex -> ex end.(), else: fn v -> v + 1 end.()
2

iex> use Exceptional.Control
...> if_exception ArgumentError.exception("error message") do
...>   fn %{message: msg} -> msg end.()
...> else
...>   fn v -> v end.()
...> end
"error message"


iex> use Exceptional.Control
...> ArgumentError.exception("error message")
...> |> if_exception do
...>   fn %{message: msg} -> msg end.()
...> else
...>   fn v -> v end.()
...> end
"error message"