Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- import contextlib
- @contextlib.contextmanager
- def make_context():
- print ' entering'
- try:
- yield {}
- except RuntimeError, err:
- print ' ERROR:', err
- finally:
- print ' exiting'
- print 'Normal:'
- with make_context() as value:
- print ' inside with statement:', value
- print '\nHandled error:'
- with make_context() as value:
- raise RuntimeError('showing example of handling an error')
- print '\nUnhandled error:'
- with make_context() as value:
- raise ValueError('this exception is not handled')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement