import sys def store_raise_exc_generator(): try: yield except Exception as exc: yield raise make = store_raise_exc_generator() next(make) try: raise Exception() except Exception as exc: try: make.throw(exc) except Exception: pass try: next(make) except Exception as exc: pass print("exc_info at exit", sys.exc_info())