[erlang-questions] string:substr/2 gives confusing error message

Hynek Vychodil vychodil.hynek@REDACTED
Fri Dec 5 12:12:27 CET 2008


I think it is worthless work add exception raise as last clause on each
function when this error occurred in same function. Different thing is when
bad argument raise exception in some subtle internal function and worse when
it is other type than function_clause. function_clause means there is not
any clause which match to your parameters and is synonymous to badarg for
me. Adding exception raise in this case is typical defensive programming and
it is not good practice in Erlang except pattern match with tagging.

On Fri, Dec 5, 2008 at 11:12 AM, Vlad Dumitrescu <vladdu55@REDACTED> wrote:

> Hi!
>
> Calling string:substr/2 with erroneous arguments gives a
> non-informative error message
>
> (w@REDACTED)1> string:substr([], 2).
> ** exception error: no function clause matching string:substr2([],2)
>
> Shouldn't it be badarg instead, or something similar?
>
> Also, the strings module documentation doesn't mention what are the
> cases when the function will fail. (A quick glance shows that there
> are other functions in the same situation).
>
> best regards,
> Vlad
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://www.erlang.org/mailman/listinfo/erlang-questions
>



-- 
--Hynek (Pichi) Vychodil
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20081205/ae38efab/attachment.htm>


More information about the erlang-questions mailing list