Example usage for javax.script ScriptException ScriptException

List of usage examples for javax.script ScriptException ScriptException

Introduction

In this page you can find the example usage for javax.script ScriptException ScriptException.

Prototype

public ScriptException(String message, String fileName, int lineNumber) 

Source Link

Document

Creates a ScriptException with message, filename and linenumber to be used in error messages.

Usage

From source file:com.thinkbiganalytics.spark.repl.ScriptEngine.java

/**
 * Checks the output stream for a compile error.
 *
 * @throws ScriptException if a compile error is found
 *///from  w  w  w.j ava  2  s  .co  m
private void checkCompileError() throws ScriptException {
    byte[] outBytes = this.out.toByteArray();

    // Look for label
    int labelIndex = ArrayUtils.indexOf(outBytes, 0, outBytes.length, LABEL, 0, LABEL.length, 0);
    if (labelIndex == -1) {
        return;
    }

    // Look for start and end of message
    int lineIndex = labelIndex + LABEL.length + 1;
    int msgStart = ArrayUtils.indexOf(outBytes, 0, outBytes.length, SEPARATOR, 0, SEPARATOR.length, lineIndex)
            + 2;
    int msgEnd = ArrayUtils.indexOf(outBytes, 0, outBytes.length, END_LINE, 0, END_LINE.length, msgStart);

    // Throw exception
    int line;
    String message;

    try {
        line = Integer.parseInt(new String(outBytes, lineIndex, msgStart - lineIndex - 2));
        message = new String(outBytes, msgStart, msgEnd - msgStart, "UTF-8");
    } catch (UnsupportedEncodingException e) {
        throw new IllegalStateException(e);
    }

    throw new ScriptException(message, "<console>", line);
}