List of usage examples for jdk.nashorn.api.scripting NashornException getLineNumber
public final int getLineNumber()
From source file:com.baasbox.service.scripting.js.Nashorn.java
License:Apache License
/** * Script call evaluation/* w w w . j ava 2s.c o m*/ * @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.eas.client.AsyncProcess.java
protected void doComplete(F aResult) { if (exceptions.isEmpty()) { if (onSuccess != null) { onSuccess.accept(aResult);/*from ww w . j ava2 s .c o m*/ } } else { if (onFailure != null) { StringBuilder eMessagesSum = new StringBuilder(); exceptions.stream().forEach((ex) -> { if (eMessagesSum.length() > 0) { eMessagesSum.append("\n"); } String message = ex.getMessage() != null && !ex.getMessage().isEmpty() ? ex.getMessage() : ex.toString(); if (ex instanceof FileNotFoundException) { message = "File or module not found: " + message; } else if (ex instanceof NashornException) { NashornException nex = (NashornException) ex; message = nex.getFileName() + ":" + nex.getLineNumber() + " " + message; } eMessagesSum.append(message); }); onFailure.accept(new IllegalStateException(eMessagesSum.toString())); } } }
From source file:com.threecrickets.scripturian.adapter.NashornAdapter.java
License:LGPL
/** * Creates an execution exception./*w ww . jav 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); }
From source file:org.eclipse.californium.actinium.jscoap.JavaScriptResource.java
License:Open Source License
private void callJSCallback(CoapExchange exchange, CoapCallback callback) { try {/*from w w w .j ava 2 s. c o m*/ callback.call(new JavaScriptCoapExchange(exchange), exchange.advanced().getRequest()); } catch (NashornException e) { exchange.respond(CoAP.ResponseCode.INTERNAL_SERVER_ERROR, e.getMessage()); System.err.println( "JavaScript error in [" + e.getFileName() + "#" + e.getLineNumber() + "]: " + e.getMessage()); throw e; } }