34 import jdk.nashorn.internal.codegen.CompilerConstants.Call;
35 import jdk.nashorn.internal.codegen.CompilerConstants.FieldAccess;
36
37 /**
38 * Exception used to implement ECMAScript "throw" from scripts. The actual thrown
39 * object from script need not be a Java exception and so it is wrapped as an
40 * instance field called "thrown" here. This exception class is also used to
41 * represent ECMA errors thrown from runtime code (for example, TypeError,
42 * ReferenceError thrown from Nashorn engine runtime).
43 */
44 @SuppressWarnings("serial")
45 public final class ECMAException extends NashornException {
46 /**
47 * Method handle pointing to the constructor {@link ECMAException#ECMAException(Object, String, int, int)},
48 */
49 public static final Call THROW_INIT = constructorNoLookup(ECMAException.class, Object.class, String.class, int.class, int.class);
50
51 /** Field handle to the{@link ECMAException#thrown} field, so that it can be accessed from generated code */
52 public static final FieldAccess THROWN = virtualField(ECMAException.class, "thrown", Object.class);
53
54 private static final String EXCEPTION_PROPERTY = "nashornException";
55
56 /** Object thrown. */
57 public final Object thrown;
58
59 /**
60 * Constructor. This is called from generated code to implement the {@code throw}
61 * instruction from generated script code
62 *
63 * @param thrown object to be thrown
64 * @param fileName script file name
65 * @param line line number of throw
66 * @param column column number of throw
67 */
68 public ECMAException(final Object thrown, final String fileName, final int line, final int column) {
69 super(ScriptRuntime.safeToString(thrown), asThrowable(thrown), fileName, line, column);
70 this.thrown = thrown;
71 setExceptionToThrown();
72 }
73
74 /**
|
34 import jdk.nashorn.internal.codegen.CompilerConstants.Call;
35 import jdk.nashorn.internal.codegen.CompilerConstants.FieldAccess;
36
37 /**
38 * Exception used to implement ECMAScript "throw" from scripts. The actual thrown
39 * object from script need not be a Java exception and so it is wrapped as an
40 * instance field called "thrown" here. This exception class is also used to
41 * represent ECMA errors thrown from runtime code (for example, TypeError,
42 * ReferenceError thrown from Nashorn engine runtime).
43 */
44 @SuppressWarnings("serial")
45 public final class ECMAException extends NashornException {
46 /**
47 * Method handle pointing to the constructor {@link ECMAException#ECMAException(Object, String, int, int)},
48 */
49 public static final Call THROW_INIT = constructorNoLookup(ECMAException.class, Object.class, String.class, int.class, int.class);
50
51 /** Field handle to the{@link ECMAException#thrown} field, so that it can be accessed from generated code */
52 public static final FieldAccess THROWN = virtualField(ECMAException.class, "thrown", Object.class);
53
54 public static final String EXCEPTION_PROPERTY = "nashornException";
55
56 /** Object thrown. */
57 public final Object thrown;
58
59 /**
60 * Constructor. This is called from generated code to implement the {@code throw}
61 * instruction from generated script code
62 *
63 * @param thrown object to be thrown
64 * @param fileName script file name
65 * @param line line number of throw
66 * @param column column number of throw
67 */
68 public ECMAException(final Object thrown, final String fileName, final int line, final int column) {
69 super(ScriptRuntime.safeToString(thrown), asThrowable(thrown), fileName, line, column);
70 this.thrown = thrown;
71 setExceptionToThrown();
72 }
73
74 /**
|