caoccao/Javet

How to obtain the value of 'error. code' in Java

Closed this issue · 4 comments

In Java

public static void main(String[] args) {
        try {
            V8Runtime v8Runtime = V8Host.getNodeInstance().createV8Runtime();
            v8Runtime.getExecutor("""
                    require('nohave')
                    """).executeVoid();
        } catch (JavetException e) {
            e.printStackTrace();
        }
    }

I have 'JavetException e', how can I obtain the value of 'code'

In Nodejs

try {
	require('nohave')
} catch (e) {
	console.log('code: ' + e.code)
}

print: code: MODULE_NOT_FOUND

I found it in 'e.getScriptingError(). getContext() .getContext()'

Does it have the potential to become a property of 'JavetScriptingError' in the future

code

I believe that 'message', 'stack', and 'code' have the same status

'JavetScriptingError' has' message 'and' stack ', but no' code '

Everything is in the context. code doesn't exist in ECMAScript, so there is no API level support.

I understand