Thursday, March 5, 2009

Dealing with SPDeletedConcurrencyException

SPDeletedConcurrencyException is an exception thrown by the SPPersistedObject Update() method.  It indicates that another processes has deleted the SPPersistedObject you are trying to update.

The questions you need to answer are:

·         Is this unexpected behavior for your application (is class not expected to be deleted)?

·         Does the removal of my object negatively impact the current operation?

If the answer to both these questions is “no”, then simply suppress this exception.

Building on yesterdays code snip:

int count = 0;
while (true)
{
    try
    {
        MySPPersistedObject obj = FindMyObject(id);
        obj.SomeOperation();
        obj.Update();
        break;
    }
    catch (SPDeletedConcurrencyException){
        // Done. This object is gone so we are finished.
        // Optional logging of condition
        break;
    }
    catch (SPUpdatedConcurrencyException)
    {
        count++;
        if (count > 10)
        {
            throw;
        }
    }
}

No comments:

Post a Comment