<html><head><meta http-equiv="Content-Type" content="text/html charset=gb2312"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">Your solution is good enough and beautiful.<div class=""><br class=""></div><div class="">Cheers,</div><div class="">Yao</div><div class=""><br class=""><div><blockquote type="cite" class=""><div class="">在 2020年3月4日,16:41,WW <<a href="mailto:kingwang98@yahoo.com" class="">kingwang98@yahoo.com</a>> 写道:</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=""></div></body></html>