diff --git a/mako/compat.py b/mako/compat.py index e26b65b1b62ab5ccfdda35139a4fe7bbaff929e7..fe277bbf05a45149e2cea2f9269b806ec968bb30 100644 --- a/mako/compat.py +++ b/mako/compat.py @@ -68,6 +68,18 @@ else: fp.close() +if py3k: + def reraise(tp, value, tb=None, cause=None): + if cause is not None: + value.__cause__ = cause + if value.__traceback__ is not tb: + raise value.with_traceback(tb) + raise value +else: + exec("def reraise(tp, value, tb=None, cause=None):\n" + " raise tp, value, tb\n") + + def exception_as(): return sys.exc_info()[1] diff --git a/mako/runtime.py b/mako/runtime.py index d7b96819d58b22b9056f0c5ed36c1846ccc8a42c..31ad557f4ee3d9ab0b488f39869c76adc95de8d7 100644 --- a/mako/runtime.py +++ b/mako/runtime.py @@ -863,7 +863,7 @@ def _render_error(template, context, error): if template.error_handler: result = template.error_handler(context, error) if not result: - raise error + compat.reraise(*sys.exc_info()) else: error_template = exceptions.html_error_template() if context._outputting_as_unicode: