Logo
programming4us
programming4us
programming4us
programming4us
Home
programming4us
XP
programming4us
Windows Vista
programming4us
Windows 7
programming4us
Windows Azure
programming4us
Windows Server
programming4us
Windows Phone
 
Windows Server

Sharepoint 2013 : Working with the CSOM (part 5) - Working with the JavaScript client object model - Handling errors

- Free product key for windows 10
- Free Product Key for Microsoft office 365
- Malwarebytes Premium 3.7.1 Serial Keys (LifeTime) 2019
11/5/2014 8:34:24 PM

Handling errors

Just like the managed client object model, the JavaScript client object model must deal with the potential for server-side errors during the round trip. Because the JavaScript client object model can only make asynchronous calls, the basic error-handling pattern involves the definition of success and failure callback methods. However, you can also use error scopes in your JavaScript. Example 11 shows how to set up error scopes in JavaScript. The sample performs the same functionality as presented in Example 4, wherein managed code was used.

Example 11. JavaScript CSOM error scopes
"use strict";

var Wingtip = window.Wingtip || {}

Wingtip.ErrorScope = function () {

//private members
var site,

scope = function () {

//Get Context
var ctx = new SP.ClientContext.get_current();

//Start Exception-Handling Scope
var e = new SP.ExceptionHandlingScope(ctx);
var s = e.startScope();

//try
var t = e.startTry();

var list1 = ctx.get_web().get_lists().getByTitle("My List");
ctx.load(list1);
list1.set_description("A new description");
list1.update();

t.dispose();

//catch
var c = e.startCatch();

var listCI = new SP.ListCreationInformation();

listCI.set_title("My List");
listCI.set_templateType(SP.ListTemplateType.announcements);
listCI.set_quickLaunchOption(SP.QuickLaunchOptions.on);

var list = ctx.get_web().get_lists().add(listCI);

c.dispose();

//finally
var f = e.startFinally();

var list2 = ctx.get_web().get_lists().getByTitle("My List");
ctx.load(list2);
list2.set_description("A new description");
list2.update();

f.dispose();

//End Exception-Handling Scope
s.dispose();

//Execute
ctx.executeQueryAsync(success, failure);

},

success = function () {
alert("Success");
},

failure = function (sender, args) {
alert(args.get_message());
}

//public interface
return {
execute: scope
}
}();


$(document).ready(function () {
Wingtip.ErrorScope.execute();
});
Other -----------------
- Managing Windows Server 2012 Systems : Configuring Roles, Role Services, and Features (part 6) - Tracking installed roles, role services, and features
- Managing Windows Server 2012 Systems : Configuring Roles, Role Services, and Features (part 5) - Installing components at the prompt
- Managing Windows Server 2012 Systems : Configuring Roles, Role Services, and Features (part 4) - Managing server binaries
- Managing Windows Server 2012 Systems : Configuring Roles, Role Services, and Features (part 3) - Adding server roles and features
- Managing Windows Server 2012 Systems : Configuring Roles, Role Services, and Features (part 2) - Installing components with Server Manager - Viewing configured roles and role services
- Managing Windows Server 2012 Systems : Configuring Roles, Role Services, and Features (part 1) - Using roles, role services, and features
- Windows Server 2012 : Configuring IPsec (part 7) - Configuring connection security rules - Monitoring IPsec
- Windows Server 2012 : Configuring IPsec (part 6) - Configuring connection security rules - Creating a custom rule, Configuring authenticated bypass
- Windows Server 2012 : Configuring IPsec (part 5) - Configuring connection security rules - Creating an authentication exemption rule, Creating a server-to-server rule, Creating a tunnel rule
- Windows Server 2012 : Configuring IPsec (part 4) - Configuring connection security rules - Types of connection security rules, Creating an isolation rule
 
 
Top 10
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 2) - Wireframes,Legends
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 1) - Swimlanes
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Formatting and sizing lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Adding shapes to lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Sizing containers
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 3) - The Other Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 2) - The Data Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 1) - The Format Properties of a Control
- Microsoft Access 2010 : Form Properties and Why Should You Use Them - Working with the Properties Window
- Microsoft Visio 2013 : Using the Organization Chart Wizard with new data
 
programming4us
Windows Vista
programming4us
Windows 7
programming4us
Windows Azure
programming4us
Windows Server