<html><head></head><body><div class="ydp51c3217byahoo-style-wrap" style="font-family:Helvetica Neue, Helvetica, Arial, sans-serif;font-size:10px;"><div dir="ltr" data-setdir="false">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"><br></div><div dir="ltr" data-setdir="false">example</div><div dir="ltr" data-setdir="false"><br></div><div dir="ltr" data-setdir="false">spec my_fun(Arg:String()) -> term().</div><div dir="ltr" data-setdir="false"><br></div><div dir="ltr" data-setdir="false">In case someone calling my_fun( atom_input), how to handle the error ?</div><div dir="ltr" data-setdir="false"><br></div><div dir="ltr" data-setdir="false">my solution:</div><div dir="ltr" data-setdir="false"><br></div><div dir="ltr" data-setdir="false">my_fun(Arg) when is_string(Arg) -> </div><div dir="ltr" data-setdir="false"> do_something.<br></div><div dir="ltr" data-setdir="false"><br></div><div dir="ltr" data-setdir="false">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"><br></div><div dir="ltr" data-setdir="false"><br></div><div dir="ltr" data-setdir="false">My question: Is my solution good enough ? Any bettter way to handle the wrong input ?</div><div dir="ltr" data-setdir="false"><br></div><div dir="ltr" data-setdir="false"><br></div><div class="ydp51c3217bsignature">Best Regards
W.W.(KingWang)</div></div></body></html>