+ class pending_raise:
+ """If rethrow is true, rethrow ex (if any), unless the body throws.
+
+ If the body does throw, make any provided ex the __context__
+ of the newer exception (assuming there's no existing
+ __context__). Ensure the exceptions have __tracebacks__.
+ (Supports Python 2 compatibility.)
+
+ """
+ def __init__(self, ex, rethrow=True):
+ self.ex = ex
+ self.rethrow = rethrow
+ def __enter__(self):
+ if self.ex:
+ add_ex_tb(self.ex)
+ def __exit__(self, exc_type, exc_value, traceback):
+ if exc_value:
+ if self.ex:
+ add_ex_tb(exc_value)
+ add_ex_ctx(exc_value, self.ex)
+ return
+ if self.rethrow and self.ex:
+ raise self.ex
+