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>";
query.set_viewXml(caml);
var listItems = targetList.getItems(query);
results = context.loadQuery(listItems, 'Include(Title, Author, ID)')
targetList = context.get_web().get_lists().getByTitle("Announcements");
tryBlock.dispose();
context.executeQueryAsync(_onSucceed, _Fail)
var catchBlock = errScope.startCatch();
catchBlock.dispose();
var finallyBlock = errScope.startFinally();
finallyBlock.dispose();
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.