Java Code Examples for org.mozilla.javascript.tools.ToolErrorReporter#getMessage()

The following examples show how to use org.mozilla.javascript.tools.ToolErrorReporter#getMessage() . 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: Main.java    From JsDroidCmd with Mozilla Public License 2.0 6 votes vote down vote up
static void evalInlineScript(Context cx, String scriptText) {
    try {
        Script script = cx.compileString(scriptText, "<command>", 1, null);
        if (script != null) {
            script.exec(cx, getShellScope());
        }
    } catch (RhinoException rex) {
        ToolErrorReporter.reportException(
                cx.getErrorReporter(), rex);
        exitCode = EXITCODE_RUNTIME_ERROR;
    } catch (VirtualMachineError ex) {
        // Treat StackOverflow and OutOfMemory as runtime errors
        ex.printStackTrace();
        String msg = ToolErrorReporter.getMessage(
                "msg.uncaughtJSException", ex.toString());
        Context.reportError(msg);
        exitCode = EXITCODE_RUNTIME_ERROR;
    }
}
 
Example 2
Source File: Main.java    From JsDroidCmd with Mozilla Public License 2.0 6 votes vote down vote up
public static void processFileNoThrow(Context cx, Scriptable scope, String filename) {
    try {
        processFile(cx, scope, filename);
    } catch (IOException ioex) {
        Context.reportError(ToolErrorReporter.getMessage(
                "msg.couldnt.read.source", filename, ioex.getMessage()));
        exitCode = EXITCODE_FILE_NOT_FOUND;
    } catch (RhinoException rex) {
        ToolErrorReporter.reportException(
                cx.getErrorReporter(), rex);
        exitCode = EXITCODE_RUNTIME_ERROR;
    } catch (VirtualMachineError ex) {
        // Treat StackOverflow and OutOfMemory as runtime errors
        ex.printStackTrace();
        String msg = ToolErrorReporter.getMessage(
                "msg.uncaughtJSException", ex.toString());
        Context.reportError(msg);
        exitCode = EXITCODE_RUNTIME_ERROR;
    }
}
 
Example 3
Source File: Main.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
static void evalInlineScript(Context cx, String scriptText) {
    try {
        Script script = cx.compileString(scriptText, "<command>", 1, null);
        if (script != null) {
            script.exec(cx, getShellScope());
        }
    } catch (RhinoException rex) {
        ToolErrorReporter.reportException(
                cx.getErrorReporter(), rex);
        exitCode = EXITCODE_RUNTIME_ERROR;
    } catch (VirtualMachineError ex) {
        // Treat StackOverflow and OutOfMemory as runtime errors
        ex.printStackTrace();
        String msg = ToolErrorReporter.getMessage(
                "msg.uncaughtJSException", ex.toString());
        Context.reportError(msg);
        exitCode = EXITCODE_RUNTIME_ERROR;
    }
}
 
Example 4
Source File: Main.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
public static void processFileNoThrow(Context cx, Scriptable scope, String filename) {
    try {
        processFile(cx, scope, filename);
    } catch (IOException ioex) {
        Context.reportError(ToolErrorReporter.getMessage(
                "msg.couldnt.read.source", filename, ioex.getMessage()));
        exitCode = EXITCODE_FILE_NOT_FOUND;
    } catch (RhinoException rex) {
        ToolErrorReporter.reportException(
                cx.getErrorReporter(), rex);
        exitCode = EXITCODE_RUNTIME_ERROR;
    } catch (VirtualMachineError ex) {
        // Treat StackOverflow and OutOfMemory as runtime errors
        ex.printStackTrace();
        String msg = ToolErrorReporter.getMessage(
                "msg.uncaughtJSException", ex.toString());
        Context.reportError(msg);
        exitCode = EXITCODE_RUNTIME_ERROR;
    }
}
 
Example 5
Source File: SwitchGenerator.java    From JsDroidCmd with Mozilla Public License 2.0 5 votes vote down vote up
private EvaluatorException on_same_pair_fail(IdValuePair a, IdValuePair b) {
    int line1 = a.getLineNumber(), line2 = b.getLineNumber();
    if (line2 > line1) { int tmp = line1; line1 = line2; line2 = tmp; }
    String error_text = ToolErrorReporter.getMessage(
        "msg.idswitch.same_string", a.id, new Integer(line2));
    return R.runtimeError(error_text, source_file, line1, null, 0);
}
 
Example 6
Source File: Main.java    From JsDroidCmd with Mozilla Public License 2.0 5 votes vote down vote up
static void processFiles(Context cx, String[] args)
{
    // define "arguments" array in the top-level object:
    // need to allocate new array since newArray requires instances
    // of exactly Object[], not ObjectSubclass[]
    Object[] array = new Object[args.length];
    System.arraycopy(args, 0, array, 0, args.length);
    Scriptable argsObj = cx.newArray(global, array);
    global.defineProperty("arguments", argsObj,
                          ScriptableObject.DONTENUM);

    for (String file: fileList) {
        try {
            processSource(cx, file);
        } catch (IOException ioex) {
            Context.reportError(ToolErrorReporter.getMessage(
                    "msg.couldnt.read.source", file, ioex.getMessage()));
            exitCode = EXITCODE_FILE_NOT_FOUND;
        } catch (RhinoException rex) {
            ToolErrorReporter.reportException(
                cx.getErrorReporter(), rex);
            exitCode = EXITCODE_RUNTIME_ERROR;
        } catch (VirtualMachineError ex) {
            // Treat StackOverflow and OutOfMemory as runtime errors
            ex.printStackTrace();
            String msg = ToolErrorReporter.getMessage(
                "msg.uncaughtJSException", ex.toString());
            Context.reportError(msg);
            exitCode = EXITCODE_RUNTIME_ERROR;
        }
    }
}
 
Example 7
Source File: Main.java    From JsDroidCmd with Mozilla Public License 2.0 5 votes vote down vote up
private void addError(String messageId, String arg)
{
    String msg;
    if (arg == null) {
        msg = ToolErrorReporter.getMessage(messageId);
    } else {
        msg = ToolErrorReporter.getMessage(messageId, arg);
    }
    addFormatedError(msg);
}
 
Example 8
Source File: SwitchGenerator.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
private EvaluatorException on_same_pair_fail(IdValuePair a, IdValuePair b) {
    int line1 = a.getLineNumber(), line2 = b.getLineNumber();
    if (line2 > line1) { int tmp = line1; line1 = line2; line2 = tmp; }
    String error_text = ToolErrorReporter.getMessage(
        "msg.idswitch.same_string", a.id, new Integer(line2));
    return R.runtimeError(error_text, source_file, line1, null, 0);
}
 
Example 9
Source File: Main.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
static void processFiles(Context cx, String[] args)
{
    // define "arguments" array in the top-level object:
    // need to allocate new array since newArray requires instances
    // of exactly Object[], not ObjectSubclass[]
    Object[] array = new Object[args.length];
    System.arraycopy(args, 0, array, 0, args.length);
    Scriptable argsObj = cx.newArray(global, array);
    global.defineProperty("arguments", argsObj,
                          ScriptableObject.DONTENUM);

    for (String file: fileList) {
        try {
            processSource(cx, file);
        } catch (IOException ioex) {
            Context.reportError(ToolErrorReporter.getMessage(
                    "msg.couldnt.read.source", file, ioex.getMessage()));
            exitCode = EXITCODE_FILE_NOT_FOUND;
        } catch (RhinoException rex) {
            ToolErrorReporter.reportException(
                cx.getErrorReporter(), rex);
            exitCode = EXITCODE_RUNTIME_ERROR;
        } catch (VirtualMachineError ex) {
            // Treat StackOverflow and OutOfMemory as runtime errors
            ex.printStackTrace();
            String msg = ToolErrorReporter.getMessage(
                "msg.uncaughtJSException", ex.toString());
            Context.reportError(msg);
            exitCode = EXITCODE_RUNTIME_ERROR;
        }
    }
}
 
Example 10
Source File: Main.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
private void addError(String messageId, String arg)
{
    String msg;
    if (arg == null) {
        msg = ToolErrorReporter.getMessage(messageId);
    } else {
        msg = ToolErrorReporter.getMessage(messageId, arg);
    }
    addFormatedError(msg);
}
 
Example 11
Source File: Global.java    From JsDroidCmd with Mozilla Public License 2.0 4 votes vote down vote up
static RuntimeException reportRuntimeError(String msgId) {
    String message = ToolErrorReporter.getMessage(msgId);
    return Context.reportRuntimeError(message);
}
 
Example 12
Source File: Global.java    From JsDroidCmd with Mozilla Public License 2.0 4 votes vote down vote up
static RuntimeException reportRuntimeError(String msgId, String msgArg)
{
    String message = ToolErrorReporter.getMessage(msgId, msgArg);
    return Context.reportRuntimeError(message);
}
 
Example 13
Source File: Global.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
static RuntimeException reportRuntimeError(String msgId) {
    String message = ToolErrorReporter.getMessage(msgId);
    return Context.reportRuntimeError(message);
}
 
Example 14
Source File: Global.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
static RuntimeException reportRuntimeError(String msgId, String msgArg)
{
    String message = ToolErrorReporter.getMessage(msgId, msgArg);
    return Context.reportRuntimeError(message);
}