Azure DocumentDB存储过程异常未被捕获

时间:2016-11-07 21:43:51

标签: azure stored-procedures azure-cosmosdb

我在DocumentDB存储过程中有这个:

function mySproc(doc) {
    let context = getContext();
    let collection = context.getCollection();
    let collectionLink = collection.getSelfLink();

    try {
        if (!collection.createDocument(collectionLink, doc, handler))
            return;
        numCreated++;
    } catch (e) {
        // Never happens.
    }
}

不幸的是,如果我故意抛出handler回调,它就不会陷入catch块。它最终会停止整个存储的proc执行。这是预期的 - 回调是否有自己的某种范围?

1 个答案:

答案 0 :(得分:0)

在像JavaScript这样的异步环境中,您通常会通过第一个参数将任何错误控制传递回回调(也就是术语中的处理程序)。如果你在你的处理程序中抛出,它将完全终止并将错误包返回给客户端。它永远不会看到你的陷阱。

如果您需要更多帮助,请展示您的处理程序。