From 77b286b2ccccc407d8ed17b0543b10f7c1ccc864 Mon Sep 17 00:00:00 2001 From: Nick Coghlan Date: Mon, 27 Jan 2014 00:53:38 +1000 Subject: Close #20105: set __traceback__ when chaining exceptions in C --- Objects/exceptions.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'Objects/exceptions.c') diff --git a/Objects/exceptions.c b/Objects/exceptions.c index bff7f0819e..2531ead50f 100644 --- a/Objects/exceptions.c +++ b/Objects/exceptions.c @@ -2689,8 +2689,11 @@ _PyErr_TrySetFromCause(const char *format, ...) * types as well, but that's quite a bit trickier due to the extra * state potentially stored on OSError instances. */ - - Py_XDECREF(tb); + /* Ensure the traceback is set correctly on the existing exception */ + if (tb != NULL) { + PyException_SetTraceback(val, tb); + Py_DECREF(tb); + } #ifdef HAVE_STDARG_PROTOTYPES va_start(vargs, format); -- cgit v1.2.1