pypy Exception games
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
>>>> class MyException(Exception): | |
.... def pr(self): | |
.... print 'hi' | |
>>>> __builtins__.FutureWarning = MyException | |
>>>> try: | |
.... raise FutureWarning | |
.... except FutureWarning as fw: | |
.... fw.pr() | |
.... | |
hi | |
>>>> __builtins__.KeyError = MyException | |
>>>> try: | |
.... {}['nope'] | |
.... except KeyError as ke: | |
.... ke.pr() | |
.... | |
Traceback (most recent call last): | |
File "<console>", line 2, in <module> | |
KeyError: 'nope' | |
# FutureWarning was caught because I threw it in Python, | |
# but KeyError wasn't because it was thrown in RPython. :/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment