Exception Handling (when to use it)
abuse at cabal.org.uk
Fri Jul 13 10:42:31 BST 2007
On Fri, Jul 13, 2007 at 12:31:34AM -0700, Ovid wrote:
> Running out of records in a table is a normal condition. If I did what he
> said and later removed exception handling, the program would have ceased
> to function because normal conditions weren't accounted for.
However I do note that Python iterators may raise a StopIteration exception
to indicate that one has reached the end of the list (/hash/whatever) being
walked. Users of the iterator do not see the exception though: they just see
normal termination of their 'for i in list:' loop. If the iterator throws a
different kind of exception, that *does* get propagated.
It feels icky from a C++ or Perl standpoint, but it seems to be the best
solution to the problem in Python.
More information about the london.pm