[Python-Dev] Exception and ABCs / issue #12029 (original) (raw)

George-Cristian Bîrzan gcbirzan at gmail.com
Fri May 11 12:33:57 CEST 2012


As per http://bugs.python.org/issue12029 , ABC registration cannot be used for exceptions. This was introduced in a commit that fixed a recursion limit problem back in 2008 (http://hg.python.org/cpython/rev/d6e86a96f9b3/#l8.10). This was later fixed in a different way and improved upon in the 2.x branch in http://hg.python.org/cpython/rev/7e86fa255fc2 and http://hg.python.org/cpython/rev/57de1ad15c54 respectively.

Applying the fix from the 2.x branch for doesn't make any tests fail, and it fixes the problem described in the bug report. There are, however, two questions about this:

before: TryRaiseExceptClass: 25ms 25ms 0.39us 0.216ms after: TryRaiseExceptException: 31ms 31ms 0.48us 0.214ms

However, that doesn't tell the whole story, since there's overhead from raising the exception. In order to find out how much actually checking slows down the checking, I ran three timeits, with the following code:

  1. try: raise ValueError() except NameError: pass except NameError: pass except ValueError: pass

  2. try: raise ValueError() except NameError: pass except ValueError: pass

  3. try: raise ValueError() except ValueError: pass

Times are in ms: before after 1 528.69 825.38 2 473.73 653.39 3 416.29 496.80 avgdiff 56.23 164.29

The numbers don't change significantly for more exception tests.

-- George-Cristian Bîrzan



More information about the Python-Dev mailing list