Skip to content

Instantly share code, notes, and snippets.

@mahmoud
Created October 14, 2011 08:12
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save mahmoud/1286533 to your computer and use it in GitHub Desktop.
pypy Exception games
>>>> 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