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

Hynek Vychodil <>
Fri Dec 5 14:27:38 CET 2008


You are right, but it means not change behavior from raise function_clause
to raise badarg but change from raise function_clause to return empty list.
It is worth decision but you change API with all consequents. I think you
agree that change to raise badarg is not solution :-)

On Fri, Dec 5, 2008 at 12:32 PM, Valentin Micic <>wrote:

> I think that depends how you want to look at it...
> One may argue that
>        string:substr([], 2 )
> does not make much sense as a statement, but then, I'd say that:
>        string:substr("1", 2 )
> does not make to much sense either, and yet it returns [].
> IMO, both functions should behave the same way, and to be pragmatic, return
> an empty list (not a badarg exception).
>
> V.
>
>
> -----Original Message-----
> From: 
> [mailto:] On Behalf Of Vlad Dumitrescu
> Sent: 05 December 2008 12:12 PM
> To: erlang-questions
> Subject: [erlang-questions] string:substr/2 gives confusing error message
>
> Hi!
>
> Calling string:substr/2 with erroneous arguments gives a
> non-informative error message
>
> ()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
> 
> http://www.erlang.org/mailman/listinfo/erlang-questions
>
> _______________________________________________
> erlang-questions mailing list
> 
> 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/3168ff34/attachment.html>


More information about the erlang-questions mailing list