Example usage for jdk.nashorn.internal.runtime ECMAException ECMAException

List of usage examples for jdk.nashorn.internal.runtime ECMAException ECMAException

Introduction

In this page you can find the example usage for jdk.nashorn.internal.runtime ECMAException ECMAException.

Prototype

public ECMAException(final Object thrown, final Throwable cause) 

Source Link

Document

Constructor.

Usage

From source file:com.baasbox.service.scripting.js.Api.java

License:Apache License

public static String execCommand(String commandStr, JsonCallback callback) {
    BaasBoxLogger.debug("Command to execute: " + commandStr);
    try {//from w w w  .  j a v  a  2s.  com
        JsonNode node = Json.mapper().readTree(commandStr);
        if (!node.isObject()) {
            BaasBoxLogger.error("Command is not an object");
            throw ECMAErrors.typeError("Invalid command");
        }
        ObjectNode o = (ObjectNode) node;
        String main = mainModule();
        if (main != null) {
            o.put("main", main);
        }
        JsonNode exec = CommandRegistry.execute(node, callback);
        String res = exec == null ? null : exec.toString();
        BaasBoxLogger.debug("Command result: " + res);
        return res;
    } catch (IOException e) {
        BaasBoxLogger.error("IoError " + ExceptionUtils.getMessage(e), e);
        throw ECMAErrors.typeError(e, "Invalid command definition");
    } catch (CommandException e) {
        BaasBoxLogger.error("CommandError: " + ExceptionUtils.getMessage(e), e);
        throw new ECMAException(ExceptionUtils.getMessage(e), e);
    }
}