[erlang-questions] string:substr/2 gives confusing error message
Fri Dec 5 14:35:23 CET 2008
On Fri, Dec 5, 2008 at 2:11 PM, mats cronqvist <> wrote:
> "Hynek Vychodil" <> writes:
> > Because:
> > Adding exception raise in this case is typical defensive programming
> > and it is not good practice in Erlang except pattern match with
> > tagging.
> so, a function raising an exception when given bad data is not good
> practice in Erlang?
Yes, absolutely. When you don't know what to do, die. see  As you wrote
below, now you think you know what to do, but in this case just do what to
do. Raise different exception is not solution. That's all.
> what gave you that impression? I'd say that the
> opposite is true. "The erlang way", as i was taught it, is to fail
> early and let the supervisor sort it out.
> also, the way i interpret "defensive programming" is when a function
> continues despite being given bad data. a typical example would be;
> string:substr("a",2) -> 
> The fact that
> behaves differently is is just silly. the best would be is they both
> failed with badarg. second best if they both returned .
You found matter of the problem. But I think both could return empty list.
--Hynek (Pichi) Vychodil
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the erlang-questions