Does anyone know how to capture and inspect a Python error object with reticulate? I'm interfacing with some Python code that will throw an error whose class inherits from Python's Exception
and contains some special fields that are needed for properly handling the error. I was hoping (naïvely) that, something like:
tryCatch({
# some reticulate code that raises a Python exception
}, error = function(e) {
print(e$my_special_field)
# handle based on my_special_field
})
... would work, where e
would be of a class extending R's error
, but rather it seems e
is of class c("Rcpp::exception", "C++Error", "error", "condition")
.
I could go lower-level and wrap the Python call out into a larger code block (executed as script) with Python-specific error-handling in place, but it'd be really nice if the Python error object is made accessible like other Python objects outside of condition-handlers.
Does anyone know if this is possible?