Josh
Josh

Reputation: 7405

Azure DocumentDB stored procedure exception not being caught

I have this in my DocumentDB stored proc:

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.
    }
}

Unfortunately, if I intentionally throw within the handler callback, it doesn't get caught in the catch block. It ends up halting the entire stored proc execution. Is that expected--does the callback have its own scope of some sort?

Upvotes: 0

Views: 193

Answers (1)

Larry Maccherone
Larry Maccherone

Reputation: 9523

In an async environment like JavaScript, you generally pass any of your error control back to the callback (aka handler in your terminology) via the first parameter. If you throw within your handler, it will completely terminate and return the error package to the client. It never sees your catch block.

If you want more help please show your handler.

Upvotes: 0

Related Questions