GJain
GJain

Reputation: 5093

How to format a throw statement in Erlang?

I am new to Erlang syntax and struggling with this. I can do this and compile:

1> throw("testing 123").
** exception throw: "testing 123"

which is of type throw/1.

I want to be able to do this:

%% I have seen this code in sample examples.
?THROW("Couldn't start process: ~p. ~n", [Reason])

I do not think there is throw/2. Then how can I define a macro like above?

Upvotes: 1

Views: 91

Answers (1)

Pascal
Pascal

Reputation: 14042

?THROW is a macro. It should be define somewhere as:

-define(THROW(Format,Params),throw(io_lib:format(Format,Params))).

In this definition, the call to io_lib:format(Format,Params) returns a single string that is used as Reason by the function throw.

Upvotes: 2

Related Questions