Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from contextlib import contextmanager
- import sys
- @contextmanager
- def supresser(*args):
- try:
- yield
- except Exception as exc:
- if(type(exc) in args):
- pass
- else:
- raise exc
- @contextmanager
- def retyper(type_from, type_to):
- try:
- yield
- except Exception as exc:
- if(type(exc) == type_from):
- new_exc = type_to(*exc.args)
- new_exc.__traceback__ = exc.__traceback__
- raise new_exc
- else:
- raise exc
- @contextmanager
- def dumper(stream):
- try:
- yield
- except Exception as exc:
- print_str = type(exc).__name__ + ': ' + str(exc) + '\n'
- stream.write(print_str)
- raise exc
Advertisement
Add Comment
Please, Sign In to add comment