<div class="gmail_quote">On Tue, Jul 31, 2012 at 1:21 PM, Terry Reedy <span dir="ltr"><<a href="mailto:tjreedy@udel.edu" target="_blank">tjreedy@udel.edu</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">

<div class="im">Another example: KeyError and IndexError are both subscript errors, but there is no SubscriptError superclass, even though both work thru the same mechanism -- __getitem__.  The reason is that there is no need for one. In 'x[y]', x is usually intented to be either a sequence or mapping, but not possibly both. In the rare cases when one wants to catch both errors, one can easily enough. To continue the example above, popping an empty list and empty set produce IndexError and KeyError respectively:</div>

</blockquote><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
  try:<br>
    while True:<br>
      process(pop())<br>
  except (KeyError, IndexError):<br>
    pass  # empty collection means we are done</blockquote><div><br></div><div>There is a base type for KeyError and IndexError: LookupError.</div><div><br></div><div><a href="http://docs.python.org/library/exceptions.html#exception-hierarchy">http://docs.python.org/library/exceptions.html#exception-hierarchy</a>
</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class="HOEnZb"><font color="#888888"><br>
<br>
-- <br>
Terry Jan Reedy<br>
<br>
<br>
<br>
-- <br>
<a href="http://mail.python.org/mailman/listinfo/python-list" target="_blank">http://mail.python.org/<u></u>mailman/listinfo/python-list</a><br>
</font></span></blockquote></div><br>