Erlang Error Handling when input argument is wrong format

bengt cean.ebengt@REDACTED
Wed Mar 4 10:02:39 CET 2020


Greetings,

Your solution is good enough.

Best Wishes,
bengt


> On 4 Mar 2020, at 09:41, WW <kingwang98@REDACTED> wrote:
> 
> 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/78f72a1e/attachment.htm>


More information about the erlang-questions mailing list