summaryrefslogtreecommitdiffstats
path: root/Objects/exceptions.c
diff options
context:
space:
mode:
authorNick Coghlan <ncoghlan@gmail.com>2014-01-26 14:53:38 (GMT)
committerNick Coghlan <ncoghlan@gmail.com>2014-01-26 14:53:38 (GMT)
commit77b286b2ccccc407d8ed17b0543b10f7c1ccc864 (patch)
tree2e95a1c03b79829ebf72698d61da997f501ef1a5 /Objects/exceptions.c
parent23e37aa7b787fd41623c4f3f1eb7ca16ded2ef96 (diff)
downloadcpython-77b286b2ccccc407d8ed17b0543b10f7c1ccc864.zip
cpython-77b286b2ccccc407d8ed17b0543b10f7c1ccc864.tar.gz
cpython-77b286b2ccccc407d8ed17b0543b10f7c1ccc864.tar.bz2
Close #20105: set __traceback__ when chaining exceptions in C
Diffstat (limited to 'Objects/exceptions.c')
-rw-r--r--Objects/exceptions.c7
1 files changed, 5 insertions, 2 deletions
diff --git a/Objects/exceptions.c b/Objects/exceptions.c
index bff7f08..2531ead 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);