<html><head><meta http-equiv="Content-Type" content="text/html; charset=us-ascii"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class="">Greetings,<br class=""><br class="">Your solution is good enough.<br class=""><br class="">Best Wishes,<br class="">bengt<br class=""><br class=""><div><br class=""><blockquote type="cite" class=""><div class="">On 4 Mar 2020, at 09:41, WW <<a href="mailto:kingwang98@yahoo.com" class="">kingwang98@yahoo.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div class=""><div class="ydp51c3217byahoo-style-wrap" style="font-family:Helvetica Neue, Helvetica, Arial, sans-serif;font-size:10px;"><div dir="ltr" data-setdir="false" class="">Hi I have a question about the error handling in erlang when input argument is in wrong format.</div><div dir="ltr" data-setdir="false" class=""><br class=""></div><div dir="ltr" data-setdir="false" class="">example</div><div dir="ltr" data-setdir="false" class=""><br class=""></div><div dir="ltr" data-setdir="false" class="">spec my_fun(Arg:String()) -> term().</div><div dir="ltr" data-setdir="false" class=""><br class=""></div><div dir="ltr" data-setdir="false" class="">In case someone calling my_fun( atom_input), how to handle the error ?</div><div dir="ltr" data-setdir="false" class=""><br class=""></div><div dir="ltr" data-setdir="false" class="">my solution:</div><div dir="ltr" data-setdir="false" class=""><br class=""></div><div dir="ltr" data-setdir="false" class="">my_fun(Arg) when is_string(Arg) -> </div><div dir="ltr" data-setdir="false" class=""> do_something.<br class=""></div><div dir="ltr" data-setdir="false" class=""><br class=""></div><div dir="ltr" data-setdir="false" class="">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}</div><div dir="ltr" data-setdir="false" class=""><br class=""></div><div dir="ltr" data-setdir="false" class=""><br class=""></div><div dir="ltr" data-setdir="false" class="">My question: Is my solution good enough ? Any bettter way to handle the wrong input ?</div><div dir="ltr" data-setdir="false" class=""><br class=""></div><div dir="ltr" data-setdir="false" class=""><br class=""></div><div class="ydp51c3217bsignature">Best Regards
W.W.(KingWang)</div></div></div></div></blockquote></div><br class=""></body></html>