Reputation: 3845
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?
Upvotes: 9
Views: 7475
Reputation: 3713
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
Upvotes: 4