Erlang Error Handling when input argument is wrong format

WW kingwang98@REDACTED
Wed Mar 4 09:41:37 CET 2020


Hi I have a question about the error handling in erlang when input argument is in wrong format.
example
spec my_fun(Arg:String()) -> term().
In case someone calling my_fun( atom_input), how to handle the error ?
my solution:
my_fun(Arg) when is_string(Arg) ->     do_something.

With the guards  the function will only take string(), when input is not a string the interface will generate run_time error   {error, function_fault}

My question: Is my solution good enough ?  Any bettter way to handle the wrong input ?

Best Regards W.W.(KingWang)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20200304/d1469311/attachment.htm>


More information about the erlang-questions mailing list