com.gargoylesoftware.htmlunit.javascript.host.Window.triggerOnError()方法的使用及代码示例

x33g5p2x  于2022-02-03 转载在 JavaScript  
字(4.5k)|赞(0)|评价(0)|浏览(176)

本文整理了Java中com.gargoylesoftware.htmlunit.javascript.host.Window.triggerOnError()方法的一些代码示例,展示了Window.triggerOnError()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Window.triggerOnError()方法的具体详情如下:
包路径:com.gargoylesoftware.htmlunit.javascript.host.Window
类名称:Window
方法名:triggerOnError

Window.triggerOnError介绍

[英]Triggers the onerror handler, if one has been set.
[中]触发OneError处理程序(如果已设置)。

代码示例

代码示例来源:origin: net.disy.htmlunit/htmlunit

/**
 * Handles an exception that occurred during execution of JavaScript code.
 * @param scriptException the exception
 */
protected void handleJavaScriptException(final ScriptException scriptException) {
  // Trigger window.onerror, if it has been set.
  final HtmlPage page = scriptException.getPage();
  if (page != null) {
    final WebWindow window = page.getEnclosingWindow();
    if (window != null) {
      final Window w = (Window) window.getScriptObject();
      if (w != null) {
        w.triggerOnError(scriptException);
      }
    }
  }
  // Throw a Java exception if the user wants us to.
  if (getWebClient().isThrowExceptionOnScriptError()) {
    throw scriptException;
  }
  // Log the error; ScriptException instances provide good debug info.
  LOG.info("Caught script exception", scriptException);
}

代码示例来源:origin: org.jvnet.hudson/htmlunit

/**
 * Handles an exception that occurred during execution of JavaScript code.
 * @param scriptException the exception
 */
protected void handleJavaScriptException(final ScriptException scriptException) {
  // Trigger window.onerror, if it has been set.
  final HtmlPage page = scriptException.getPage();
  if (page != null) {
    final WebWindow window = page.getEnclosingWindow();
    if (window != null) {
      final Window w = (Window) window.getScriptObject();
      if (w != null) {
        w.triggerOnError(scriptException);
      }
    }
  }
  // Throw a Java exception if the user wants us to.
  if (getWebClient().isThrowExceptionOnScriptError()) {
    throw scriptException;
  }
  // Log the error; ScriptException instances provide good debug info.
  LOG.info("Caught script exception", scriptException);
}

代码示例来源:origin: org.jenkins-ci/htmlunit

/**
 * Handles an exception that occurred during execution of JavaScript code.
 * @param scriptException the exception
 */
protected void handleJavaScriptException(final ScriptException scriptException) {
  // Trigger window.onerror, if it has been set.
  final HtmlPage page = scriptException.getPage();
  if (page != null) {
    final WebWindow window = page.getEnclosingWindow();
    if (window != null) {
      final Window w = (Window) window.getScriptObject();
      if (w != null) {
        w.triggerOnError(scriptException);
      }
    }
  }
  // Throw a Java exception if the user wants us to.
  if (getWebClient().isThrowExceptionOnScriptError()) {
    throw scriptException;
  }
  // Log the error; ScriptException instances provide good debug info.
  LOG.info("Caught script exception", scriptException);
}

代码示例来源:origin: net.sourceforge.htmlunit/htmlunit

/**
 * Handles an exception that occurred during execution of JavaScript code.
 * @param scriptException the exception
 * @param triggerOnError if true, this triggers the onerror handler
 */
protected void handleJavaScriptException(final ScriptException scriptException, final boolean triggerOnError) {
  // Trigger window.onerror, if it has been set.
  final HtmlPage page = scriptException.getPage();
  if (triggerOnError && page != null) {
    final WebWindow window = page.getEnclosingWindow();
    if (window != null) {
      final Window w = window.getScriptableObject();
      if (w != null) {
        try {
          w.triggerOnError(scriptException);
        }
        catch (final Exception e) {
          handleJavaScriptException(new ScriptException(page, e, null), false);
        }
      }
    }
  }
  getWebClient().getJavaScriptErrorListener().scriptException(page, scriptException);
  // Throw a Java exception if the user wants us to.
  if (getWebClient().getOptions().isThrowExceptionOnScriptError()) {
    throw scriptException;
  }
  // Log the error; ScriptException instances provide good debug info.
  LOG.info("Caught script exception", scriptException);
}

代码示例来源:origin: HtmlUnit/htmlunit

/**
 * Handles an exception that occurred during execution of JavaScript code.
 * @param scriptException the exception
 * @param triggerOnError if true, this triggers the onerror handler
 */
protected void handleJavaScriptException(final ScriptException scriptException, final boolean triggerOnError) {
  // Trigger window.onerror, if it has been set.
  final HtmlPage page = scriptException.getPage();
  if (triggerOnError && page != null) {
    final WebWindow window = page.getEnclosingWindow();
    if (window != null) {
      final Window w = window.getScriptableObject();
      if (w != null) {
        try {
          w.triggerOnError(scriptException);
        }
        catch (final Exception e) {
          handleJavaScriptException(new ScriptException(page, e, null), false);
        }
      }
    }
  }
  getWebClient().getJavaScriptErrorListener().scriptException(page, scriptException);
  // Throw a Java exception if the user wants us to.
  if (getWebClient().getOptions().isThrowExceptionOnScriptError()) {
    throw scriptException;
  }
  // Log the error; ScriptException instances provide good debug info.
  LOG.info("Caught script exception", scriptException);
}

相关文章