Example usage for jdk.nashorn.api.scripting NashornException getColumnNumber

List of usage examples for jdk.nashorn.api.scripting NashornException getColumnNumber

Introduction

In this page you can find the example usage for jdk.nashorn.api.scripting NashornException getColumnNumber.

Prototype

public final int getColumnNumber() 

Source Link

Document

Get the column for this NashornException

Usage

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

License:Apache License

/**
 * Script call evaluation/*ww w  .  jav  a 2  s. c om*/
 * @param call
 * @return
 * @throws ScriptEvalException
 */
ScriptResult eval(ScriptCall call) throws ScriptEvalException {
    try {
        ScriptObjectMirror moduleRef = getModule(call);

        if (call.event == null) {
            return null;
        }

        Object result = emitEvent(moduleRef, call.event, call.eventData);
        ScriptResult scriptResult = mMapper.convertResult(result);
        call.validate(scriptResult);
        if (BaasBoxLogger.isTraceEnabled())
            BaasBoxLogger.trace("ScriptResult: %s", scriptResult.toString());
        return scriptResult;
    } catch (Throwable err) {
        if (err instanceof NashornException) {
            if (BaasBoxLogger.isTraceEnabled())
                BaasBoxLogger.trace("Error in script");

            Throwable cause = err.getCause();
            NashornException exc = ((NashornException) err);
            String scriptStack = NashornException.getScriptStackString(exc);
            scriptStack = ExceptionUtils.getFullStackTrace(exc);
            int columnNumber = exc.getColumnNumber();
            int lineNumber = exc.getLineNumber();
            String fileName = exc.getFileName();
            String message = exc.getMessage();
            String errorMessage = String.format("ScriptError: '%s' at: <%s>%d:%d\n%s", message, fileName,
                    lineNumber, columnNumber, scriptStack);
            throw new ScriptEvalException(errorMessage, err);
        }
        throw new ScriptEvalException(ExceptionUtils.getFullStackTrace(err), err);
    }
}

From source file:com.threecrickets.scripturian.adapter.NashornAdapter.java

License:LGPL

/**
 * Creates an execution exception.//from ww w  .  j  a  v a  2 s  .  c om
 * 
 * @param x
 *        The exception
 * @param documentName
 *        The document name
 * @return The execution exception
 */
public static ExecutionException createExecutionException(Throwable x, String documentName) {
    Throwable cause = x.getCause();
    if (cause != null) {
        if (cause instanceof ExecutionException)
            return (ExecutionException) cause;
        if (x instanceof NashornException) {
            NashornException nx = (NashornException) x;
            return new ExecutionException(nx.getFileName(), nx.getLineNumber(), nx.getColumnNumber(),
                    nx.getMessage(), cause);
        } else
            return new ExecutionException(documentName, x);
    } else if (x instanceof NashornException) {
        NashornException nx = (NashornException) x;
        return new ExecutionException(nx.getFileName(), nx.getLineNumber(), nx.getColumnNumber(),
                nx.getMessage(), cause);
    } else
        return new ExecutionException(documentName, x);
}