I’d like to catch errors thrown by Python side in Pyodide. To handle them in JavaScript side, i.e. use try-catch syntax in JS, how should I get the exception object?
For example, when NameError
is occurred, the way to check its type by JS side is preferred.
try {
pyodide.runPython(code)
} catch (e) {
// Is this available?
if (e instanceof NameError) { // Use Python's exception types
... // handle NameError
} else if (e instanceof IndexError) {
...
}
}