def g1(e): yield 1 raise e def g2(): yield 1 def append_error(e): it = g1(e) while 1: try: value = next(it) except RuntimeError as e: it = g2() next(it) except StopIteration: return def main(): append_error(RuntimeError("These exception objects are prepended")) append_error(RuntimeError("to the stack of chained errors")) raise ValueError("HAI WORLD") if __name__ == '__main__': main()