I am trying to implement try - catch in CSOM - JavaScript, I have the following code:
var ctx = new SP.ClientContext.get_current();
var exScope= new SP.ExceptionHandlingScope(ctx);
var s= exScope.startScope();
//try
var t= exScope.startTry();
var contactsList = ctx.get_web().get_lists().getByTitle(_title);
ctx.load(contactsList);
contactsList.set_description("My Contacts List");
contactsList.update();
t.dispose();
//catch
var c = exScope.startCatch();
var listCI = new SP.ListCreationInformation();
listCI.set_title("Contacts List");
listCI.set_description("My Contacts List");
listCI.set_templateType(SP.ListTemplateType.contacts);
listCI.set_quickLaunchOption(SP.QuickLaunchOptions.on);
ctx.get_web().get_lists().add(listCI);
c.dispose();
//finally
var f= exScope.startFinally();
f.dispose();
s.dispose();
//Execute
ctx.executeQueryAsync(onEnsureSuccess, onEnsureFail);
I am defining exeption scope, and try scope to make sure the list exists, if it doesn't a catch will be thrown and it will create a list, so I am handling all errors on the server. What happens is i have an error in onEnsureFail that the list exists, should I get no error? Shouldn't the try block only be executed and the catch not be executed? I don't know what's going on with my code, any help?

0 commentaires:
Enregistrer un commentaire