Java Reference
In-Depth Information
Listing 4-4 shows another version of the program in Listing 4-3. This time, you use
only catch block and print the error's details using the Nashorn extensions for the
Error object.
Listing 4-4. The Contents of the File factorial_test2.js
// factorial_test2.js
load("factorial.js");
try {
// throw new TypeError("A type error occurred.");
var fact3 = factorial(3);
print("Factorial of 3 is", fact3);
var factHello = factorial("Hello");
print("Factorial of 3 is", factHello);
}
catch (e) {
printf("Line %d, column %d, file %s. %s",
e.lineNumber, e.columnNumber, e.fileName, e.message);
}
Factorial of 3 is 6
Line 10, column 8, file factorial.js. The number must be an integer.
Found:Hello
The debugger Statement
The debugger statement is for debugging purpose. It does not take any action by itself. If
a debugger is active, the implementation may cause a breakpoint but it is not required to
do so when it encounters a debugger statement. The syntax is:
debugger;
The NetBeans 8.0 IDE supports the debugger statement in debug mode. I will show
how to debug Nashorn scripts using a debugger statement in Chapter 13.
 
Search WWH ::




Custom Search