com.gargoylesoftware.htmlunit.WebClient.isThrowExceptionOnScriptError()方法的使用及代码示例

x33g5p2x  于2022-02-02 转载在 其他  
字(5.6k)|赞(0)|评价(0)|浏览(134)

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

WebClient.isThrowExceptionOnScriptError介绍

[英]Indicates if an exception should be thrown when a script execution fails (the default) or if it should be caught and just logged to allow page execution to continue.
[中]指示脚本执行失败时是否应引发异常(默认设置),或者是否应捕获并记录异常以允许页面执行继续。

代码示例

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

public final Object run(final Context cx) {
  final Boolean javaScriptAlreadyRunning = javaScriptRunning_.get();
  javaScriptRunning_.set(Boolean.TRUE);
  try {
    cx.putThreadLocal(KEY_STARTING_SCOPE, scope_);
    cx.putThreadLocal(KEY_STARTING_PAGE, htmlPage_);
    synchronized (htmlPage_) { // 2 scripts can't be executed in parallel for one page
      final Object response = doRun(cx);
      processPostponedActions();
      return response;
    }
  }
  catch (final Exception e) {
    handleJavaScriptException(new ScriptException(htmlPage_, e, getSourceCode(cx)));
    return null;
  }
  catch (final TimeoutError e) {
    if (getWebClient().isThrowExceptionOnScriptError()) {
      throw new RuntimeException(e);
    }
    LOG.info("Caught script timeout error", e);
    return null;
  }
  finally {
    javaScriptRunning_.set(javaScriptAlreadyRunning);
  }
}

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

public final Object run(final Context cx) {
  final Boolean javaScriptAlreadyRunning = javaScriptRunning_.get();
  javaScriptRunning_.set(Boolean.TRUE);
  try {
    cx.putThreadLocal(KEY_STARTING_SCOPE, scope_);
    cx.putThreadLocal(KEY_STARTING_PAGE, htmlPage_);
    synchronized (htmlPage_) { // 2 scripts can't be executed in parallel for one page
      final Object response = doRun(cx);
      processPostponedActions();
      return response;
    }
  }
  catch (final Exception e) {
    handleJavaScriptException(new ScriptException(htmlPage_, e, getSourceCode(cx)));
    return null;
  }
  catch (final TimeoutError e) {
    if (getWebClient().isThrowExceptionOnScriptError()) {
      throw new RuntimeException(e);
    }
    LOG.info("Caught script timeout error", e);
    return null;
  }
  finally {
    javaScriptRunning_.set(javaScriptAlreadyRunning);
  }
}

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

public final Object run(final Context cx) {
  final Boolean javaScriptAlreadyRunning = javaScriptRunning_.get();
  javaScriptRunning_.set(Boolean.TRUE);
  try {
    cx.putThreadLocal(KEY_STARTING_SCOPE, scope_);
    cx.putThreadLocal(KEY_STARTING_PAGE, htmlPage_);
    synchronized (htmlPage_) { // 2 scripts can't be executed in parallel for one page
      final Object response = doRun(cx);
      processPostponedActions();
      return response;
    }
  }
  catch (final Exception e) {
    handleJavaScriptException(new ScriptException(htmlPage_, e, getSourceCode(cx)));
    return null;
  }
  catch (final TimeoutError e) {
    if (getWebClient().isThrowExceptionOnScriptError()) {
      throw new RuntimeException(e);
    }
    LOG.info("Caught script timeout error", e);
    return null;
  }
  finally {
    javaScriptRunning_.set(javaScriptAlreadyRunning);
  }
}

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

LOG.error("Unable to build URL for script src tag [" + srcAttribute + "]");
if (getWebClient().isThrowExceptionOnScriptError()) {
  throw new ScriptException(this, e);

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

LOG.error("Unable to build URL for script src tag [" + srcAttribute + "]");
if (getWebClient().isThrowExceptionOnScriptError()) {
  throw new ScriptException(this, e);

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

LOG.error("Unable to build URL for script src tag [" + srcAttribute + "]");
if (getWebClient().isThrowExceptionOnScriptError()) {
  throw new ScriptException(this, e);

代码示例来源: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);
}

相关文章

WebClient类方法