Why does array.index("foo") raise an exception instead of returning -1 if no element is found?
<p>If I want to find the array index of a given item i Python, I'll do something like this:</p>

<pre><code>a = ["boo", "foo", "bar", "foz"]
i = a.index("foo")
</code></pre>

<p>and <code>i</code> would be <code>1</code></p>

<p>If I'm looking for a non existing item a <code>ValueError</code> exception is raised. </p>

<p><strong>Question:</strong> Why is it preferable to raise an exception instead of returning <code>-1</code> (as JavaScript's equivalent function <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/indexOf" rel="nofollow noreferrer"><code>indexOf</code></a> does)? I find it much easier to check for -1 instead of wrapping code blocks in try-catch.</p>