Necessity of ``pass''

Michael Hudson mwh21 at cam.ac.uk
Fri Aug 27 13:42:42 EDT 1999


grahamclemo at my-deja.com writes:

> After a bit of experimentation I found you can replace except: with
> except 0: (I doubt anyone has raise 0 in their code) and except
> ZeroDivisionError: with except 0:#ZeroDivisionError: etc.

If you did have "raise 0" in your code, chances are it wasn't doing
what you were expecting:

>>> try:
...  raise 0
... except 0:
...  print "caught"
...
Traceback (innermost last):
  File "<stdin>", line 2, in ?
TypeError: exceptions must be strings, classes, or instances

so "except 0:" is s good block-that-will-never-catch. One for the back
of the mind, I think.

> (I'm surprised Python silently accepts *any* value in except
> statements)

It's probably too awkward (& not particularly helpful) to ban them.

Regards,
Michael




More information about the Python-list mailing list