Wednesday, November 12, 2014

what to expect except to accept

Any object can be the target of an except, not just subclasses of BaseException.

>>> try:
...    raise Exception("these are all fine!")
... except dict as not_exception:
...    pass
... except 42 as not_a_type:
...    pass
... except type as super_meta:
...    pass
...
Traceback (most recent call last):
  File "<stdin>", line 2, in <module>
Exception: these are all fine!


No comments:

Post a Comment