Prev | Index | NextRaising Exceptions
>>> try:
... raise NameError, "pretending a NameError occurred"
... except NameError, err:
... print "An error occurred: %s" % err
...
An error occurred: pretending a NameError occurred
Slightly more complex
>>> try:
... raise ValueError, "pretending a ValueError occurred"
... except NameError, err:
... print "A NameError occurred: %s" % err
... except ValueError, err:
... print "A ValueError occurred: %s" % err
...
A ValueError occurred: pretending a ValueError occurred
An Introduction To Python