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

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


Because:

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 12:17 PM, Vlad Dumitrescu <vladdu55@REDACTED> wrote:

> On Fri, Dec 5, 2008 at 12:12, Hynek Vychodil <vychodil.hynek@REDACTED>
> wrote:
> > I think it is worthless work add exception raise as last clause on each
> > function when this error occurred in same function.
>
> >> (w@REDACTED)1> string:substr([], 2).
> >> ** exception error: no function clause matching string:substr2([],2)
>
> Except it's not the same function: notice the error refers to string2,
> not to string.
>
> Yes, it's relatively easy to check the code and see what's going
> wrong, but then any documentation is redundant, as one could check the
> code...
>
> In any case, badarg is the standard exception thrown in similar cases,
> so why not be consistent?
>
> regards,
> Vlad
>



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


More information about the erlang-questions mailing list