On Tue, 15 Nov 2005 21:59:44 -0500, Roy Smith wrote: > In article <[EMAIL PROTECTED]>, > Steven D'Aprano <[EMAIL PROTECTED]> wrote: > >> try: >> for item in obj: >> do_stuff(item) >> except TypeError, msg: >> if msg == "iteration over non-sequence": >> handle_non_iterator() >> else: >> # re-raise the exception >> raise > > That's the obvious solution, but it's a poor one because it depends on an > undocumented feature of the language. What's documented is that TypeError > is raised; it's not documented what the text of the message will be.
It would be nice if The Powers That Be would document the specific error messages, so that we could rely on them in total safety. But even without that, the consequences aren't especially dire. What happens if the error message changes in some future version of Python? Then the error won't be caught, the exception will be re-raised, and your testing will catch it immediately. It isn't the ideal solution, but it is a solution. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list