May 2018
Intermediate to advanced
412 pages
9h 3m
English
You can raise an exception using the raise function. At its simplest, you pass it a string and it generates an exception of type RuntimeError.
| | iex> raise "Giving up" |
| | ** (RuntimeError) Giving up |
| | erl_eval.erl:572: :erl_eval.do_apply/6 |
You can also pass the type of the exception, along with other optional fields. All exceptions implement at least the message field.
| | iex> raise RuntimeError |
| | ** (RuntimeError) runtime error |
| | erl_eval.erl:572: :erl_eval.do_apply/6 |
| | iex> raise RuntimeError, message: "override message" |
| | ** (RuntimeError) override message |
| | erl_eval.erl:572: :erl_eval.do_apply/6 |
You can intercept exceptions using the try function. It takes a block of code to execute, and optional ...
Read now
Unlock full access