[graalvm-users] Question about GraalVM JavaScript usage Exceptions

Michael Itkin mitkin at opentext.com
Fri Feb 11 17:01:43 UTC 2022


Hello,

I am evaluating GraalVM Java Script potential usage within our product.  We are considering using GraalVM Java Script to replace Nashorn Java Script which is discontinued in Java 17
(no longer part of Java).

For the purposes of this question I am using Java 11 in testing.
We have a product that uses Java Script to control logic flow within Java application.

That is our Java written product can invoke Java Script and from within Java Script we may call back to Java Classes / methods.
So far this is the description of general setup.  To use GraalVM in the integration we add a bunch of GraalVM etc. jars to our Java product class path (module path).

Now for the question.

Within Java Script we sometimes do
try {
       some java script code;
} catch (exception) {
       lib.logError("Some message", exception);
}
lib.logError is our code that ends up calling into Java Code and passes the message and Java Script Exception Object.

Now in Nashorn and Rhino we're able to get info from the Java Script created exception Object passed into Java.

However in GraalVM we get for exception Object com.oracle.truffle.polyglot.PolyglotMap that in the guestObject member variable contains JSErrorObject
which is DynamicObject<JSError> and has the information we need to extract for logging purposes (for our program report log)

The above info about 'exception' Java Object I obtained from Java (Eclipse) debugger

PoliglotMap has a public method called getGuestObject() (from web search).

However PoliglotMap class is not public.

Thus while I can see info under debugger there seems to be
no way for me to obtain it (details of exception from Java Script) programmatically.

So that is my question - how to process GraalVM JavaScript Exception objects in our Java Application so we can extract the
information for logging purposes.

Thanks in advance for your help,

Mike
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://oss.oracle.com/pipermail/graalvm-users/attachments/20220211/28ef7ec8/attachment.html>


More information about the GraalVM-Users mailing list