Exceptional v2.1.3 Exceptional.Raise View Source

Raise an exception if one has been propagated, otherwise continue

Convenience uses

Everything:

use Exceptional.Raise

Only named functions (raise_or_continue!):

use Exceptional.Raise, only: :named_functions

Only operators (>>>):

use Exceptional.Raise, only: :operators

Link to this section Summary

Functions

An operator alias of raise_or_continue!

Define a function and automatically generate a variant that raises

Raise an exception, otherwise return plain value

raise if an exception, otherwise continue computation

Link to this section Functions

Link to this macro

maybe_exception >>> continue View Source (macro)

An operator alias of raise_or_continue!

Examples

iex> use Exceptional.Raise
...> 1 >>> fn x -> x + 1 end.()
2

iex> use Exceptional.Raise
...> %ArgumentError{message: "raise me"} >>> fn x -> x + 1 end.()
** (ArgumentError) raise me
Link to this macro

def!(head, list) View Source (macro)

Define a function and automatically generate a variant that raises

Examples

iex> defmodule Foo do
...>   use Exceptional
...>
...>   def! foo(a), do: a
...> end
...>
...> Foo.foo([1, 2, 3])
[1, 2, 3]

iex> defmodule Bar do
...>   use Exceptional
...>
...>   def! bar(a), do: a
...> end
...>
...> Bar.bar(%ArgumentError{message: "raise me"})
%ArgumentError{message: "raise me"}

iex> defmodule Baz do
...>   use Exceptional
...>
...>   def! baz(a), do: a
...> end
...>
...> Baz.baz!([1, 2, 3])
[1, 2, 3]

iex> defmodule Quux do
...>   use Exceptional
...>
...>   def! quux(a), do: a
...> end
...>
...> Quux.quux!(%ArgumentError{message: "raise me"})
** (ArgumentError) raise me
Link to this function

ensure!(maybe_exception) View Source

Raise an exception, otherwise return plain value

Examples

iex> ensure!([1, 2, 3])
[1, 2, 3]

iex> ensure!(%ArgumentError{message: "raise me"})
** (ArgumentError) raise me
Link to this macro

raise_or_continue!(maybe_exception, continue) View Source (macro)

raise if an exception, otherwise continue computation.

Examples

iex> use Exceptional.Raise
...> raise_or_continue!(1, fn x -> x + 1 end.())
2

iex> use Exceptional.Raise
...> %ArgumentError{message: "raise me"}
...> |> raise_or_continue!(fn x -> x + 1 end.())
** (ArgumentError) raise me