How to capture errors in Promise in Java?
Closed this issue · 5 comments
rongrong1000 commented
public static void main(String[] args) {
try (V8Runtime v8Runtime = V8Host.getNodeInstance().createV8Runtime()) {
v8Runtime.getExecutor("""
async function a() {
bbb()
}
a()
""").execute();
} catch (Throwable e) {
e.printStackTrace();
}
}
If an error occurs, the JVM will shut down
If the content of JavaScript is not controlled
What should I do?
Thanks
caoccao commented
You may get it by the Promise
returned by that execute()
, and you must call await()
to pump the event loop so that V8 can actually process the async task queue.
Please refer to this doc for detail.
rongrong1000 commented
Thank you very much. The problem has been resolved.
rongrong1000 commented
Can I still know his sourceLine
and resource
and startColumn
and endColumn
for this situation, i need them
The error type I have captured now is V8ValueError
rongrong1000 commented
Thank you very much for your help