java.lang.Object
java.lang.Throwable
java.lang.Exception
java.lang.RuntimeException
org.openjdk.nashorn.api.scripting.NashornException
- All Implemented Interfaces:
Serializable
This is base exception for all Nashorn exceptions. These originate from
user's ECMAScript code. Example: script parse errors, exceptions thrown from
scripts. Note that ScriptEngine methods like "eval", "invokeMethod",
"invokeFunction" will wrap this as ScriptException and throw it. But, there
are cases where user may need to access this exception (or implementation
defined subtype of this). For example, if java interface is implemented by a
script object or Java access to script object properties via java.util.Map
interface. In these cases, user code will get an instance of this or
implementation defined subclass.
- Since:
- 1.8u40
- See Also:
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
NashornException
(String msg, String fileName, int line, int column) Constructor to initialize error message, file name, line and column numbers.protected
NashornException
(String msg, Throwable cause) Constructor to initialize error message and cause exception.protected
NashornException
(String msg, Throwable cause, String fileName, int line, int column) Constructor to initialize error message, cause exception, file name, line and column numbers. -
Method Summary
Modifier and TypeMethodDescriptionfinal int
Get the column for thisNashornException
Return the underlying ECMA error object, if available.final String
Get the source file name for thisNashornException
final int
Get the line number for thisNashornException
static StackTraceElement[]
getScriptFrames
(Throwable exception) Returns array javascript stack frames from the given exception object.static String
getScriptStackString
(Throwable exception) Return a formatted script stack trace string with frames information separated by '\n'protected Object
Get the thrown object.final void
setColumnNumber
(int column) Set the column for thisNashornException
void
setEcmaError
(Object ecmaError) Return the underlying ECMA error object, if available.final void
setFileName
(String fileName) Set the source file name for thisNashornException
final void
setLineNumber
(int line) Set the line number for thisNashornException
Methods inherited from class java.lang.Throwable
addSuppressed, fillInStackTrace, getCause, getLocalizedMessage, getMessage, getStackTrace, getSuppressed, initCause, printStackTrace, printStackTrace, printStackTrace, setStackTrace, toString
-
Constructor Details
-
NashornException
Constructor to initialize error message, file name, line and column numbers.- Parameters:
msg
- exception messagefileName
- file nameline
- line numbercolumn
- column number
-
NashornException
Constructor to initialize error message, cause exception, file name, line and column numbers.- Parameters:
msg
- exception messagecause
- exception causefileName
- file nameline
- line numbercolumn
- column number
-
NashornException
Constructor to initialize error message and cause exception.- Parameters:
msg
- exception messagecause
- exception cause
-
-
Method Details
-
getFileName
Get the source file name for thisNashornException
- Returns:
- the file name
-
setFileName
Set the source file name for thisNashornException
- Parameters:
fileName
- the file name
-
getLineNumber
public final int getLineNumber()Get the line number for thisNashornException
- Returns:
- the line number
-
setLineNumber
public final void setLineNumber(int line) Set the line number for thisNashornException
- Parameters:
line
- the line number
-
getColumnNumber
public final int getColumnNumber()Get the column for thisNashornException
- Returns:
- the column number
-
setColumnNumber
public final void setColumnNumber(int column) Set the column for thisNashornException
- Parameters:
column
- the column number
-
getScriptFrames
Returns array javascript stack frames from the given exception object.- Parameters:
exception
- exception from which stack frames are retrieved and filtered- Returns:
- array of javascript stack frames
-
getScriptStackString
Return a formatted script stack trace string with frames information separated by '\n'- Parameters:
exception
- exception for which script stack string is returned- Returns:
- formatted stack trace string
-
getThrown
Get the thrown object. Subclass responsibility- Returns:
- thrown object
-
getEcmaError
Return the underlying ECMA error object, if available.- Returns:
- underlying ECMA Error object's mirror or whatever was thrown from script such as a String, Number or a Boolean.
-
setEcmaError
Return the underlying ECMA error object, if available.- Parameters:
ecmaError
- underlying ECMA Error object's mirror or whatever was thrown from script such as a String, Number or a Boolean.
-