1

I am trying to use ExceptionHandlingScope in a basic Managed client side crud I am getting the error -

Incorrect Usage of Exception Handling Scopes

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            var username = "admin";
            SecureString sPwd = new SecureString();

            foreach (var c in "password")
                sPwd.AppendChar(c);

            SharePointOnlineCredentials cred = new SharePointOnlineCredentials(username, sPwd);


            ClientContext ctx = new ClientContext("sharepoint site");

            ctx.Credentials = cred;
            ExceptionHandlingScope eScope = new ExceptionHandlingScope(ctx);
            using (eScope.StartScope())
            {
                using (eScope.StartTry())
                {
                    var listCol = ctx.Web.Lists;
                    CamlQuery query = new CamlQuery();
                    query.ViewXml = "<View><Query><Where><Eq>" +
                                        "<FieldRef Name='ID' /><Value Type='Number'>3</Value>"
                                        + "</Eq></Where></Query></View>";
                    var list = listCol.GetByTitle("Employehe");
                    var itemCol = list.GetItems(query);
                    ctx.Load(list);
                    ctx.Load(itemCol);
                }
                using (eScope.StartCatch())
                {
                    var msg = eScope.ErrorMessage;
                }
                using (eScope.StartFinally())
                {
                    Console.ReadKey();
                }
                ctx.ExecuteQuery();
            }

        }
    }
}
2

As per this: http://ranaictiu-technicalblog.blogspot.in/2010/08/sharepoint-2010-exception-handling.html, there only seem to be try, catch and finally in the scope. Try putting the executeQuery outside the StartScope.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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