<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css" style="display:none;"> P {margin-top:0;margin-bottom:0;} </style>
</head>
<body dir="ltr">
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 14pt; color: rgb(0, 0, 0);">
Hello,</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 14pt; color: rgb(0, 0, 0);">
<br>
</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 14pt; color: rgb(0, 0, 0);">
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</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 14pt; color: rgb(0, 0, 0);">
(no longer part of Java).</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 14pt; color: rgb(0, 0, 0);">
<br>
</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 14pt; color: rgb(0, 0, 0);">
For the purposes of this question I am using Java 11 in testing.</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 14pt; color: rgb(0, 0, 0);">
We have a product that uses Java Script to control logic flow within Java application.</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 14pt; color: rgb(0, 0, 0);">
<br>
</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 14pt; color: rgb(0, 0, 0);">
That is our Java written product can invoke Java Script and from within Java Script we may call back to Java Classes / methods.</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 14pt; color: rgb(0, 0, 0);">
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).</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 14pt; color: rgb(0, 0, 0);">
<br>
</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 14pt; color: rgb(0, 0, 0);">
Now for the question.</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 14pt; color: rgb(0, 0, 0);">
<br>
</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 14pt; color: rgb(0, 0, 0);">
Within Java Script we sometimes do</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 14pt; color: rgb(0, 0, 0);">
try {</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 14pt; color: rgb(0, 0, 0);">
some java script code;</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 14pt; color: rgb(0, 0, 0);">
} catch (exception) {</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 14pt; color: rgb(0, 0, 0);">
lib.logError("Some message", exception);</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 14pt; color: rgb(0, 0, 0);">
}</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 14pt; color: rgb(0, 0, 0);">
lib.logError is our code that ends up calling into Java Code and passes the message and Java Script Exception Object.</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 14pt; color: rgb(0, 0, 0);">
<br>
</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 14pt; color: rgb(0, 0, 0);">
Now in Nashorn and Rhino we're able to get info from the Java Script created exception Object passed into Java.</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 14pt; color: rgb(0, 0, 0);">
<br>
</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 14pt; color: rgb(0, 0, 0);">
However in GraalVM we get for exception Object com.oracle.truffle.polyglot.PolyglotMap that in the guestObject member variable contains JSErrorObject</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 14pt; color: rgb(0, 0, 0);">
which is DynamicObject<JSError> and has the information we need to extract for logging purposes (for our program report log)</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 14pt; color: rgb(0, 0, 0);">
<br>
</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 14pt; color: rgb(0, 0, 0);">
The above info about 'exception' Java Object I obtained from Java (Eclipse) debugger</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 14pt; color: rgb(0, 0, 0);">
</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 14pt; color: rgb(0, 0, 0);">
PoliglotMap has a public method called getGuestObject() (from web search).</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 14pt; color: rgb(0, 0, 0);">
<br>
</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 14pt; color: rgb(0, 0, 0);">
However PoliglotMap class is not public.</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 14pt; color: rgb(0, 0, 0);">
<br>
</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 14pt; color: rgb(0, 0, 0);">
Thus while I can see info under debugger there seems to be</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 14pt; color: rgb(0, 0, 0);">
no way for me to obtain it (details of exception from Java Script) programmatically.</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 14pt; color: rgb(0, 0, 0);">
<br>
</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 14pt; color: rgb(0, 0, 0);">
So that is my question - how to process GraalVM JavaScript Exception objects in our Java Application so we can extract the </div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 14pt; color: rgb(0, 0, 0);">
information for logging purposes. </div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 14pt; color: rgb(0, 0, 0);">
<br>
</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 14pt; color: rgb(0, 0, 0);">
<span style="color: rgb(0, 0, 0); font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 14pt;">Thanks in advance for your help,</span><br>
</div>
<div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 14pt; color: rgb(0, 0, 0);">
<br>
</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 14pt; color: rgb(0, 0, 0);">
Mike</div>
<div id="Signature">
<div>
<div style="color:rgb(0,0,0); font-family:Calibri,Arial,Helvetica,sans-serif; font-size:12pt">
<span></span></div>
</div>
</div>
</div>
</body>
</html>