Exceptional v2.1.3 Exceptional.Control View Source

Exception control flow

Convenience uses

Everything:

use Exceptional.Control

Link to this section Summary

Functions

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

Link to this section Functions

Link to this macro

branch(maybe_exception, list) View Source (macro)

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
Link to this macro

if_exception(maybe_exception, list) View Source (macro)

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"