本文介绍了Marklogic如何在抛出异常后继续循环的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道引发异常和文档总数失败后如何继续循环.

I would like to know how to continue looping after throwing exception and document fail at total count.

示例:使文档010291.xml在计数4000处失败,然后再次继续循环.

example: fail document 010291.xml at count 4000 and continue loop again.

xquery version "1.0-ml";
try {
  let $uris := cts:uris((),(),
                 cts:and-query(
                   cts:collection-query("/TRA")
                 )
  )[1 to 200000]

  for $uri in $uris
  return
    if (fn:exists(doc($uri))) then ()
    else $uri,

  xdmp:elapsed-time()
} catch($err) {
  "received the following exception: ", $err
}

推荐答案

将try-catch语句放入循环内

Put the try-catch statement inside the loop

xquery version "1.0-ml";

let $uris := cts:uris((),(),
               cts:and-query(
                 cts:collection-query("/TRA")
               )
)[1 to 200000]

for $uri in $uris
return
  try{(
        if (fn:exists(doc($uri)))
        then ()
        else $uri,
        xdmp:elapsed-time()
      )
  } catch($err) {
    "received the following exception: ", $err
  }

这篇关于Marklogic如何在抛出异常后继续循环的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-13 00:34