Erlang Error Handling when input argument is wrong format

by by@REDACTED
Wed Mar 4 10:09:49 CET 2020


Your solution is good enough and beautiful.

Cheers,
Yao

> 在 2020年3月4日,16:41,WW <kingwang98@REDACTED> 写道:
> 
> 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/5702d15e/attachment.htm>


More information about the erlang-questions mailing list