How to throw an exception in Erlang?
erlang, exception
Solution
This is from raising Erlang exceptions.
Example of raising an Erlang exception with `exit(Why)`.
-module(exceptions).
-export([sample_error/0]).
sample_error() -> throw(“some bad happened”).
Now lets compile our exceptions module, invoke the sample_error() function and observe >the output of the raised exception.
erlc –o ebin src/exceptions.erl
erl –pa ebin
1> exceptions:sample_error().
** exception throw: "some bad happened"
in function exceptions:sample_error/0
Problem
I'm new to Erlang and I found how to handle exceptions in a Users Guide, but not how to throw them. Is it possible to define and then throw my own exception?