Java Code Examples for com.gargoylesoftware.htmlunit.ScriptException#getFailingLineNumber()

The following examples show how to use com.gargoylesoftware.htmlunit.ScriptException#getFailingLineNumber() . 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: Window.java    From htmlunit with Apache License 2.0 5 votes vote down vote up
/**
 * Triggers the {@code onerror} handler, if one has been set.
 * @param e the error that needs to be reported
 */
public void triggerOnError(final ScriptException e) {
    final Object o = getOnerror();
    if (o instanceof Function) {
        final Function f = (Function) o;
        String msg = e.getMessage();
        final String url = e.getPage().getUrl().toExternalForm();

        final int line = e.getFailingLineNumber();
        final int column = e.getFailingColumnNumber();

        Object jsError = e.getMessage();
        if (e.getCause() instanceof JavaScriptException) {
            msg = "uncaught exception: " + e.getCause().getMessage();
            jsError = ((JavaScriptException) e.getCause()).getValue();
        }
        else if (e.getCause() instanceof EcmaError) {
            msg = "uncaught " + e.getCause().getMessage();

            final EcmaError ecmaError = (EcmaError) e.getCause();
            final Scriptable err = Context.getCurrentContext().newObject(this, "Error");
            ScriptableObject.putProperty(err, "message", ecmaError.getMessage());
            ScriptableObject.putProperty(err, "fileName", ecmaError.sourceName());
            ScriptableObject.putProperty(err, "lineNumber", Integer.valueOf(ecmaError.lineNumber()));
            jsError = err;
        }

        final Object[] args = {msg, url, Integer.valueOf(line), Integer.valueOf(column), jsError};
        f.call(Context.getCurrentContext(), this, this, args);
    }
}
 
Example 2
Source File: Window.java    From HtmlUnit-Android with Apache License 2.0 5 votes vote down vote up
/**
 * Triggers the {@code onerror} handler, if one has been set.
 * @param e the error that needs to be reported
 */
public void triggerOnError(final ScriptException e) {
    final Object o = getOnerror();
    if (o instanceof Function) {
        final Function f = (Function) o;
        String msg = e.getMessage();
        final String url = e.getPage().getUrl().toExternalForm();

        final int line = e.getFailingLineNumber();
        final int column = e.getFailingColumnNumber();

        Object jsError = e.getMessage();
        if (e.getCause() instanceof JavaScriptException) {
            msg = "uncaught exception: " + e.getCause().getMessage();
            jsError = ((JavaScriptException) e.getCause()).getValue();
        }
        else if (e.getCause() instanceof EcmaError) {
            msg = "uncaught " + e.getCause().getMessage();

            final EcmaError ecmaError = (EcmaError) e.getCause();
            final Scriptable err = Context.getCurrentContext().newObject(this, "Error");
            ScriptableObject.putProperty(err, "message", ecmaError.getMessage());
            ScriptableObject.putProperty(err, "fileName", ecmaError.sourceName());
            ScriptableObject.putProperty(err, "lineNumber", Integer.valueOf(ecmaError.lineNumber()));
            jsError = err;
        }

        final Object[] args = new Object[] {msg, url, Integer.valueOf(line), Integer.valueOf(column), jsError};
        f.call(Context.getCurrentContext(), this, this, args);
    }
}