Java Reference
In-Depth Information
try {
var fact3 = factorial(3);
print("Factorial of 3 is", fact3);
var factHello = factorial("Hello");
print("Factorial of 3 is", factHello);
}
catch (e if e instanceof RangeError) {
print("A RangeError has occurred.", e.message);
print("Error:", e.message);
}
catch (e if e instanceof TypeError) {
print("A TypeError has occurred.", e.message);
}
catch (e) {
print(e.message);
}
Factorial of 3 is 6
A TypeError has occurred. The number must be an integer. Found:Hello
Nashorn extends the Error object provided by ECMAScript. It add several useful
properties to get the details of the error thrown. Table 4-9 lists such properties with their
descriptions.
Table 4-9. The List of the Proeprties of Error Object in Nashorn
Property
Type
Description
lineNumber
Number
The line number in the source code from where the
error object was thrown
columnNumber
Number
The column number in the source code from where
the error object was thrown
fileName
String
The file name of the source script
stack
String
The script stack trace as a string
printStackTrace() function
Prints full stack trace, including all Java frames, from
where error was thrown from
getStackTrace()
Returns an array of java.lang.StackTraceElement
instance for ECMAScript frames only
function
dumpStack()
function
Prints stack trace of the current thread as the
java.lang.Thread.dumpStack() method does in Java.
The dumpStack() is a function property of the Error
object and you will need to call it as Error.dumpStack()
 
 
Search WWH ::




Custom Search