Java Code Examples for javax.script.ScriptException#initCause()

The following examples show how to use javax.script.ScriptException#initCause() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: NashornScriptEngine.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
private static void throwAsScriptException(final Exception e, final Global global) throws ScriptException {
    if (e instanceof ScriptException) {
        throw (ScriptException)e;
    } else if (e instanceof NashornException) {
        final NashornException ne = (NashornException)e;
        final ScriptException se = new ScriptException(
            ne.getMessage(), ne.getFileName(),
            ne.getLineNumber(), ne.getColumnNumber());
        ne.initEcmaError(global);
        se.initCause(e);
        throw se;
    } else if (e instanceof RuntimeException) {
        throw (RuntimeException)e;
    } else {
        // wrap any other exception as ScriptException
        throw new ScriptException(e);
    }
}
 
Example 2
Source File: NashornScriptEngine.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
private static void throwAsScriptException(final Exception e, final Global global) throws ScriptException {
    if (e instanceof ScriptException) {
        throw (ScriptException)e;
    } else if (e instanceof NashornException) {
        final NashornException ne = (NashornException)e;
        final ScriptException se = new ScriptException(
            ne.getMessage(), ne.getFileName(),
            ne.getLineNumber(), ne.getColumnNumber());
        ne.initEcmaError(global);
        se.initCause(e);
        throw se;
    } else if (e instanceof RuntimeException) {
        throw (RuntimeException)e;
    } else {
        // wrap any other exception as ScriptException
        throw new ScriptException(e);
    }
}
 
Example 3
Source File: NashornScriptEngine.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
private static void throwAsScriptException(final Exception e, final Global global) throws ScriptException {
    if (e instanceof ScriptException) {
        throw (ScriptException)e;
    } else if (e instanceof NashornException) {
        final NashornException ne = (NashornException)e;
        final ScriptException se = new ScriptException(
            ne.getMessage(), ne.getFileName(),
            ne.getLineNumber(), ne.getColumnNumber());
        ne.initEcmaError(global);
        se.initCause(e);
        throw se;
    } else if (e instanceof RuntimeException) {
        throw (RuntimeException)e;
    } else {
        // wrap any other exception as ScriptException
        throw new ScriptException(e);
    }
}
 
Example 4
Source File: NashornScriptEngine.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
private static void throwAsScriptException(final Exception e, final Global global) throws ScriptException {
    if (e instanceof ScriptException) {
        throw (ScriptException)e;
    } else if (e instanceof NashornException) {
        final NashornException ne = (NashornException)e;
        final ScriptException se = new ScriptException(
            ne.getMessage(), ne.getFileName(),
            ne.getLineNumber(), ne.getColumnNumber());
        ne.initEcmaError(global);
        se.initCause(e);
        throw se;
    } else if (e instanceof RuntimeException) {
        throw (RuntimeException)e;
    } else {
        // wrap any other exception as ScriptException
        throw new ScriptException(e);
    }
}
 
Example 5
Source File: NashornScriptEngine.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
private static void throwAsScriptException(final Exception e, final Global global) throws ScriptException {
    if (e instanceof ScriptException) {
        throw (ScriptException)e;
    } else if (e instanceof NashornException) {
        final NashornException ne = (NashornException)e;
        final ScriptException se = new ScriptException(
            ne.getMessage(), ne.getFileName(),
            ne.getLineNumber(), ne.getColumnNumber());
        ne.initEcmaError(global);
        se.initCause(e);
        throw se;
    } else if (e instanceof RuntimeException) {
        throw (RuntimeException)e;
    } else {
        // wrap any other exception as ScriptException
        throw new ScriptException(e);
    }
}
 
Example 6
Source File: HandlebarsScriptEngine.java    From sling-samples with Apache License 2.0 6 votes vote down vote up
@Override
public Object eval(String script, ScriptContext context) throws ScriptException {
    final Resource resource = (Resource) context.getBindings(ScriptContext.ENGINE_SCOPE).get(SlingBindings.RESOURCE);
    final PrintWriter out = (PrintWriter) context.getBindings(ScriptContext.ENGINE_SCOPE).get(SlingBindings.OUT);

    try {
        final Handlebars handlebars = setupHandlebars();
        final Template template = handlebars.compileInline(script);
        out.println(template.apply(getData(resource)));
    } catch(IOException ioe) {
        final ScriptException up = new ScriptException("IOException in eval");
        up.initCause(ioe);
        throw up;
    }
    return null;
}
 
Example 7
Source File: HandlebarsScriptEngine.java    From sling-samples with Apache License 2.0 6 votes vote down vote up
/** We might do this with a BindingsValuesProvider? */
private Map<?, ?> getData(Resource r) throws ScriptException {
    // Request resource.json and convert the result to Maps
    String jsonString = null;
    try {
        jsonString =
            new ServletInternalRequest(factory.getServletResolver(), r)
            .withExtension("json")
            .execute()
            .getResponseAsString()
        ;
    } catch(Exception e) {
        final ScriptException up = new ScriptException("Internal request failed");
        up.initCause(e);
        log.info("getData() failed", up);
        throw up;
    }
    final Map<?, ?> result = JsonReader.jsonToMaps(jsonString);
    log.debug("getData() returns a Map with {} keys", result.keySet().size());
    return result;
}
 
Example 8
Source File: NashornScriptEngine.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
private static void throwAsScriptException(final Exception e, final Global global) throws ScriptException {
    if (e instanceof ScriptException) {
        throw (ScriptException)e;
    } else if (e instanceof NashornException) {
        final NashornException ne = (NashornException)e;
        final ScriptException se = new ScriptException(
            ne.getMessage(), ne.getFileName(),
            ne.getLineNumber(), ne.getColumnNumber());
        ne.initEcmaError(global);
        se.initCause(e);
        throw se;
    } else if (e instanceof RuntimeException) {
        throw (RuntimeException)e;
    } else {
        // wrap any other exception as ScriptException
        throw new ScriptException(e);
    }
}
 
Example 9
Source File: NashornScriptEngine.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
private static void throwAsScriptException(final Exception e) throws ScriptException {
    if (e instanceof ScriptException) {
        throw (ScriptException)e;
    } else if (e instanceof NashornException) {
        final NashornException ne = (NashornException)e;
        final ScriptException se = new ScriptException(
            ne.getMessage(), ne.getFileName(),
            ne.getLineNumber(), ne.getColumnNumber());
        se.initCause(e);
        throw se;
    } else if (e instanceof RuntimeException) {
        throw (RuntimeException)e;
    } else {
        // wrap any other exception as ScriptException
        throw new ScriptException(e);
    }
}
 
Example 10
Source File: NashornScriptEngine.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
private static void throwAsScriptException(final Exception e) throws ScriptException {
    if (e instanceof ScriptException) {
        throw (ScriptException)e;
    } else if (e instanceof NashornException) {
        final NashornException ne = (NashornException)e;
        final ScriptException se = new ScriptException(
            ne.getMessage(), ne.getFileName(),
            ne.getLineNumber(), ne.getColumnNumber());
        se.initCause(e);
        throw se;
    } else if (e instanceof RuntimeException) {
        throw (RuntimeException)e;
    } else {
        // wrap any other exception as ScriptException
        throw new ScriptException(e);
    }
}
 
Example 11
Source File: NashornScriptEngine.java    From jdk8u_nashorn with GNU General Public License v2.0 6 votes vote down vote up
private static void throwAsScriptException(final Exception e, final Global global) throws ScriptException {
    if (e instanceof ScriptException) {
        throw (ScriptException)e;
    } else if (e instanceof NashornException) {
        final NashornException ne = (NashornException)e;
        final ScriptException se = new ScriptException(
            ne.getMessage(), ne.getFileName(),
            ne.getLineNumber(), ne.getColumnNumber());
        ne.initEcmaError(global);
        se.initCause(e);
        throw se;
    } else if (e instanceof RuntimeException) {
        throw (RuntimeException)e;
    } else {
        // wrap any other exception as ScriptException
        throw new ScriptException(e);
    }
}
 
Example 12
Source File: NashornScriptEngine.java    From nashorn with GNU General Public License v2.0 6 votes vote down vote up
private static void throwAsScriptException(final Exception e) throws ScriptException {
    if (e instanceof ScriptException) {
        throw (ScriptException)e;
    } else if (e instanceof NashornException) {
        final NashornException ne = (NashornException)e;
        final ScriptException se = new ScriptException(
            ne.getMessage(), ne.getFileName(),
            ne.getLineNumber(), ne.getColumnNumber());
        se.initCause(e);
        throw se;
    } else if (e instanceof RuntimeException) {
        throw (RuntimeException)e;
    } else {
        // wrap any other exception as ScriptException
        throw new ScriptException(e);
    }
}
 
Example 13
Source File: HandlebarsScriptEngine.java    From sling-samples with Apache License 2.0 5 votes vote down vote up
@Override
public Object eval(Reader reader, ScriptContext context) throws ScriptException {
    try {
        return eval(IOUtils.toString(reader), context);
    } catch(IOException ioe) {
        final ScriptException up = new ScriptException("IOException in eval");
        up.initCause(ioe);
        throw up;
    }
}
 
Example 14
Source File: ScriptEvaluator.java    From kite with Apache License 2.0 5 votes vote down vote up
private static void throwScriptCompilationException(String parseLocation, String msg, Throwable t) 
    throws ScriptException {
  
  if (t == null) {
    throw new ScriptException("Cannot compile script: " + parseLocation + " caused by " + msg);
  } else {
    ScriptException se = new ScriptException("Cannot compile script: " + parseLocation + " caused by " + msg);
    se.initCause(t);
    throw se;
  }
}
 
Example 15
Source File: ScriptEvaluator.java    From kite with Apache License 2.0 5 votes vote down vote up
private static void throwScriptExecutionException(String parseLocation, Object[] params, Throwable e) 
    throws ScriptException {
  
  ScriptException se = new ScriptException("Cannot execute script: " + parseLocation + " for params " + Arrays.asList(params).toString());
  se.initCause(e);
  throw se;
}