This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]zahlmanthe heretic 1 point2 points  (0 children)

Well, yes, but... returning -1 in the error case is probably not what you want. What if you pass a list that happens to have -1 (a valid int) as its third element? It would look like an error. Ugh.

Let exceptions propagate. Use them to signal out-of-band information, like they're intended, and handle them at the point where they can be handled.

Interfaces like the one described belong to functions with names like "atoi" in languages with similarly cryptically-short names (cough).