How to make an exception in Erlang?

I'm new to Erlang, and I found how to handle exceptions in the User Guide, but not how to throw them. Is it possible to identify and then throw my own exception?

+5
source share
2 answers

this is from raising erlang exceptions

An example of creating an Erlang exception with an exit (why).

-module(exceptions).

-export([sample_error/0]).

sample_error() -> throw("some bad happened").

Now let's compile our exception module, call 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
+2
source

Take a look at http://learnyousomeerlang.com/errors-and-exceptions . Under the heading "Exception Correction"

+6
source

All Articles