Class NashornException

  • All Implemented Interfaces:
    java.io.Serializable

    public abstract class NashornException
    extends java.lang.RuntimeException
    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:
    Serialized Form
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      protected NashornException​(java.lang.String msg, java.lang.String fileName, int line, int column)
      Constructor to initialize error message, file name, line and column numbers.
      protected NashornException​(java.lang.String msg, java.lang.Throwable cause)
      Constructor to initialize error message and cause exception.
      protected NashornException​(java.lang.String msg, java.lang.Throwable cause, java.lang.String fileName, int line, int column)
      Constructor to initialize error message, cause exception, file name, line and column numbers.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      int getColumnNumber()
      Get the column for this NashornException
      java.lang.Object getEcmaError()
      Return the underlying ECMA error object, if available.
      java.lang.String getFileName()
      Get the source file name for this NashornException
      int getLineNumber()
      Get the line number for this NashornException
      static java.lang.StackTraceElement[] getScriptFrames​(java.lang.Throwable exception)
      Returns array javascript stack frames from the given exception object.
      static java.lang.String getScriptStackString​(java.lang.Throwable exception)
      Return a formatted script stack trace string with frames information separated by '\n'
      protected java.lang.Object getThrown()
      Get the thrown object.
      void setColumnNumber​(int column)
      Set the column for this NashornException
      void setEcmaError​(java.lang.Object ecmaError)
      Return the underlying ECMA error object, if available.
      void setFileName​(java.lang.String fileName)
      Set the source file name for this NashornException
      void setLineNumber​(int line)
      Set the line number for this NashornException
      • Methods inherited from class java.lang.Throwable

        addSuppressed, fillInStackTrace, getCause, getLocalizedMessage, getMessage, getStackTrace, getSuppressed, initCause, printStackTrace, printStackTrace, printStackTrace, setStackTrace, toString
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Constructor Detail

      • NashornException

        protected NashornException​(java.lang.String msg,
                                   java.lang.String fileName,
                                   int line,
                                   int column)
        Constructor to initialize error message, file name, line and column numbers.
        Parameters:
        msg - exception message
        fileName - file name
        line - line number
        column - column number
      • NashornException

        protected NashornException​(java.lang.String msg,
                                   java.lang.Throwable cause,
                                   java.lang.String fileName,
                                   int line,
                                   int column)
        Constructor to initialize error message, cause exception, file name, line and column numbers.
        Parameters:
        msg - exception message
        cause - exception cause
        fileName - file name
        line - line number
        column - column number
      • NashornException

        protected NashornException​(java.lang.String msg,
                                   java.lang.Throwable cause)
        Constructor to initialize error message and cause exception.
        Parameters:
        msg - exception message
        cause - exception cause
    • Method Detail

      • getFileName

        public final java.lang.String getFileName()
        Get the source file name for this NashornException
        Returns:
        the file name
      • setFileName

        public final void setFileName​(java.lang.String fileName)
        Set the source file name for this NashornException
        Parameters:
        fileName - the file name
      • getLineNumber

        public final int getLineNumber()
        Get the line number for this NashornException
        Returns:
        the line number
      • setLineNumber

        public final void setLineNumber​(int line)
        Set the line number for this NashornException
        Parameters:
        line - the line number
      • getColumnNumber

        public final int getColumnNumber()
        Get the column for this NashornException
        Returns:
        the column number
      • setColumnNumber

        public final void setColumnNumber​(int column)
        Set the column for this NashornException
        Parameters:
        column - the column number
      • getScriptFrames

        public static java.lang.StackTraceElement[] getScriptFrames​(java.lang.Throwable exception)
        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

        public static java.lang.String getScriptStackString​(java.lang.Throwable exception)
        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

        protected java.lang.Object getThrown()
        Get the thrown object. Subclass responsibility
        Returns:
        thrown object
      • getEcmaError

        public java.lang.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

        public void setEcmaError​(java.lang.Object ecmaError)
        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.