]> granicus.if.org Git - python/commitdiff
Simplify example of PyErr_Fetch() use
authorAntoine Pitrou <solipsis@pitrou.net>
Tue, 30 Jul 2013 18:09:03 +0000 (20:09 +0200)
committerAntoine Pitrou <solipsis@pitrou.net>
Tue, 30 Jul 2013 18:09:03 +0000 (20:09 +0200)
Doc/extending/newtypes.rst

index cb20bce43509d87d401ebcb9c3a9504637b12699..d11b40890c9700de508de7d9222af11a40d2067d 100644 (file)
@@ -962,10 +962,9 @@ done.  This can be done using the :c:func:`PyErr_Fetch` and
 
        if (self->my_callback != NULL) {
            PyObject *err_type, *err_value, *err_traceback;
-           int have_error = PyErr_Occurred() ? 1 : 0;
 
-           if (have_error)
-               PyErr_Fetch(&err_type, &err_value, &err_traceback);
+           /* This saves the current exception state */
+           PyErr_Fetch(&err_type, &err_value, &err_traceback);
 
            cbresult = PyObject_CallObject(self->my_callback, NULL);
            if (cbresult == NULL)
@@ -973,8 +972,8 @@ done.  This can be done using the :c:func:`PyErr_Fetch` and
            else
                Py_DECREF(cbresult);
 
-           if (have_error)
-               PyErr_Restore(err_type, err_value, err_traceback);
+           /* This restores the saved exception state */
+           PyErr_Restore(err_type, err_value, err_traceback);
 
            Py_DECREF(self->my_callback);
        }