__init__ method and raising exceptions
Scott David Daniels
Scott.Daniels at Acm.Org
Fri Apr 1 11:48:31 EST 2005
Vikram wrote:
>>I can't use 'break' or 'continue' in a class method, nor can I return a
>>boolean value from __init__() to check for errors within the for-loop.
>>How would I be able to stop the current iteration and continue with the
>>next after reporting an error?
>
>
> maybe i don't fully understand your qn but why don't you let __init__ of
> your class raise an exception and then catch it in the outer for loop and
> continue. something like:
>
> for i in ...
> try:
> foo()
> except:
except (ValueError, TypeError), error:
> continue
Use something like the above, (always expect certain kinds of errors)
lest you accidentally capture an real attempt to stop the program
such as the exception a Control-C causes.
-Scott David Daniels
Scott.Daniels at Acm.Org
More information about the Python-list
mailing list