@@ -251,6 +251,18 @@ TVM_DLL void TVMAPISetLastError(const char* msg);
251251 */
252252TVM_DLL void TVMAPISetLastPythonError (void * py_object );
253253
254+ /*! \brief Return the previous python error, if any.
255+ *
256+ * Used to propagate the original Python exception to a python
257+ * try/except, when there are C++ stack frames between the location thro
258+ *
259+ * \return The previous argument passed during the most recent call to
260+ * TVMAPISetLastPythonError. If TVMAPISetLastPythonError has not
261+ * been called, or if TVMDropLastPythonError has been called since
262+ * the most recent to TVMAPISetLastPythonError, returns nullptr.
263+ */
264+ TVM_DLL void * TVMGetLastPythonError ();
265+
254266/*!
255267 * \brief return str message of the last error
256268 * all function in this file will return 0 when success
@@ -261,6 +273,42 @@ TVM_DLL void TVMAPISetLastPythonError(void* py_object);
261273 * \return error info
262274 */
263275TVM_DLL const char * TVMGetLastError (void );
276+
277+ /*!
278+ * \brief Return the backtrace of the most recent error
279+ *
280+ * Returns the backtrace of the most recent error, if an error exists,
281+ * and the error contains a backtrace. If no error exists or the
282+ * error does not contain a backtrace, returns nullptr.
283+ *
284+ * \return The backtrace of the most recent error
285+ */
286+ TVM_DLL const char * TVMGetLastBacktrace ();
287+
288+ /*!
289+ * \brief Remove the propagated python error, if any
290+ *
291+ * Removes the TVM-held reference to a thrown python exception object.
292+ * Because these objects contain references to the stack frames from
293+ * which the exception was thrown, maintaining a reference to an
294+ * exception object prevents any local python variables from being
295+ * garbage-collected. After retrieving the object using
296+ * TVMGetLastPythonError, the Python FFI interface uses this method to
297+ * clear the TVM-held reference to the exception, to allow garbage
298+ * collection to continue.
299+ */
300+ TVM_DLL void TVMDropLastPythonError ();
301+
302+ /*! \brief Re-throw the most recent error.
303+ *
304+ * If an error was previously set using TVMAPISetLastError or
305+ * TVMAPISetLastPythonError, re-throw the error. This is similar to
306+ * `LOG(FATAL) << TVMGetLastError()`, but includes handling to
307+ * propagate a python exception across C++ stack frames, or to append
308+ * a stack trace to an error message.
309+ */
310+ TVM_DLL void TVMThrowLastError ();
311+
264312/*!
265313 * \brief Load module from file.
266314 * \param file_name The file name to load the module from.
0 commit comments