Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to throw an exception in Erlang?

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?

like image 412
akalenuk Avatar asked Jun 02 '12 09:06

akalenuk


Video Answer


1 Answers

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
like image 166
PresleyDias Avatar answered Oct 18 '22 00:10

PresleyDias