Pages

Wednesday, November 3, 2010

Error Handling in Sharepoint 2010 via Programming (Object Model)

SharePoint exceptions are derived from the SPException class.


Below code gives you example for write error logging details to the SharePoint Unified Logging Service (ULS) logs.


void ErrorEntry()
{

        try
        {
             //Development code

        }
       catch (Exception ex)
       {
             SPDiagnosticsCategory diagnosticsCat = new SPDiagnosticsCategory("categoryName" ,  TraceSeverity.Monitorable , EventSeverity.Error);

SPDiagnosticsService.Local.WriteEvent(1 , diagnosticsCat , EventSeverity.Error , "Error Message" , ex.StackTrace);

       }
}

Disha Shah

No comments:

Post a Comment