I am trying to implement try/catch scope in my JSOM, but I am getting the error message in the question's title.

Below is my code:

        errScope = new SP.ExceptionHandlingScope(context);
        var scopeStart = errScope.startScope();

        var tryBlock = errScope.startTry();
            var targetList = context.get_web().get_lists().getByTitle("Announcements");
            //constructing caml
            var query = new SP.CamlQuery();
            var caml = "<View><Query><Where><Neq><FieldRef Name='Title'/>";
            caml += "<Value Type='Text'>Excluded</Value></Neq></Where></Query>";
            caml += "<RowLimit>2</RowLimit>";
            caml += "</View>";
            var listItems = targetList.getItems(query);
            results = context.loadQuery(listItems, 'Include(Title, Author, ID)')
            targetList = context.get_web().get_lists().getByTitle("Announcements");
        context.executeQueryAsync(_onSucceed, _Fail)

        var catchBlock = errScope.startCatch();

        var finallyBlock = errScope.startFinally();

When it reaches the end of the try block, it throws the error:

Uncaught Error: Incorrect usage of exception handling scope.

Also I don't know what are the best practices to put in the catch block and finally block.

1 Answer 1


You should not add context.executeQueryAsync(_onSucceed, _Fail); inside the scope of exception. Wait until you dispose everything then call the method as it's not part of exception handling.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.