Module jdk.scripting.nashorn
Package jdk.nashorn.api.scripting

## Class NashornException

- java.lang.Object
- - java.lang.Throwable
  - - java.lang.Exception
    - - java.lang.RuntimeException
      - - jdk.nashorn.api.scripting.NashornException

- All Implemented Interfaces:
    `Serializable`

      public abstract class NashornException
      extends 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​(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

    All Methods Static Methods Instance Methods Concrete Methods
    Modifier and Type | Method | Description
    --- | --- | ---
    `int` | `getColumnNumber​()` | Get the column for this `NashornException`
    `Object` | `getEcmaError​()` | Return the underlying ECMA error object, if available.
    `String` | `getFileName​()` | Get the source file name for this `NashornException`
    `int` | `getLineNumber​()` | Get the line number for this `NashornException`
    `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` | `getThrown​()` | Get the thrown object.
    `void` | `setColumnNumber​(int column)` | Set the column for this `NashornException`
    `void` | `setEcmaError​(Object ecmaError)` | Return the underlying ECMA error object, if available.
    `void` | `setFileName​(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.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

    - ### Methods inherited from class java.lang.Throwable

      `addSuppressed, fillInStackTrace, getCause, getLocalizedMessage, getMessage, getStackTrace, getSuppressed, initCause, printStackTrace, printStackTrace, printStackTrace, setStackTrace, toString`

- - ### Constructor Detail

    - #### NashornException

          protected NashornException​(String msg,
                                     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​(String msg,
                                     Throwable cause,
                                     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​(String msg,
                                     Throwable cause)

      Constructor to initialize error message and cause exception.
      Parameters:
        `msg` - exception message
        `cause` - exception cause

  - ### Method Detail

    - #### getFileName

          public final String getFileName​()

      Get the source file name for this `NashornException`
      Returns:
        the file name

    - #### setFileName

          public final void setFileName​(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 StackTraceElement[] getScriptFrames​(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 String getScriptStackString​(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 Object getThrown​()

      Get the thrown object. Subclass responsibility
      Returns:
        thrown object

    - #### getEcmaError

          public 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​(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.