+ PyObject *py_exc_cause_value;
+ PyObject *py_exc_type = NULL;
+ PyObject *py_exc_tb = NULL;
+ GString *gstr = NULL;
+
+ /* If this exception has a cause, handle that one first. */
+ py_exc_cause_value = PyException_GetCause(py_exc_value);
+ if (py_exc_cause_value) {
+ restore_current_thread_error_and_append_exception_chain_recursive(
+ py_exc_cause_value, self_component_class,
+ self_component, self_message_iterator, module_name);
+ }
+
+ /*
+ * If the raised exception is a bt2.Error, restore the wrapped error.
+ */
+ if (PyErr_GivenExceptionMatches(py_exc_value, py_mod_bt2_exc_error_type)) {
+ PyObject *py_error_swig_ptr;
+ const bt_error *error;
+ int ret;
+
+ /*
+ * We never raise a bt2.Error with a cause: it should be the
+ * end of the chain.
+ */
+ BT_ASSERT(!py_exc_cause_value);
+
+ /*
+ * We steal the error object from the exception, to move
+ * it back as the current thread's error.
+ */
+ py_error_swig_ptr = PyObject_GetAttrString(py_exc_value, "_ptr");
+ BT_ASSERT(py_error_swig_ptr);
+
+ ret = PyObject_SetAttrString(py_exc_value, "_ptr", Py_None);
+ BT_ASSERT(ret == 0);
+
+ ret = SWIG_ConvertPtr(py_error_swig_ptr, (void **) &error,
+ SWIGTYPE_p_bt_error, 0);
+ BT_ASSERT(ret == 0);
+
+ BT_CURRENT_THREAD_MOVE_ERROR_AND_RESET(error);
+
+ Py_DECREF(py_error_swig_ptr);
+ }
+
+ py_exc_type = PyObject_Type(py_exc_value);
+ py_exc_tb = PyException_GetTraceback(py_exc_value);