SharePoint 2010: Responsible error handling


Some will say that the responsible exception handling is no exception handling. This is specially true in SharePoint, which already has a fine logging infrastructure and error handling mechanism.

However, when building custom SharePoint applications we might have to change the default behavior on exceptions.

In this article we show how to play nice with the SharePoint logging infrastructure when building custom error handlers.


In most cases you are better off letting SharePoint handle the exception. By default, SharePoint will prompt a modal popup with brief message and a correlation id.

Default error message

This behavior is adequate when you need to stop the current process. However if your need the process to continue even after an exception you have no alternative but to implement your own exception handler.

Putting your code in a try/catch block might solve the flow problem. However you prevent the error from making it to the SharePoint logs.

The sample below shows how to send events to the SharePoint logs with the appropriate correlation id.


The Correlation Id is associated with the executing request and will allow administrators to track the flow of the events in the logs.

The value of the Correlation Id can only be accessed through a native function. Sample below:

The result, in this case is a custom error message in the page and yet a standard log message with the corresponding correlation id in the SharePoint Logs:

Custom Error message:

Custom inline error message with correlation id

Log entry:

Custom log with correlation id


In the next post we'll get into a detailed example of custom SharePoint logging.

comments powered by Disqus


Under Construction

About Me

Martin here. I'm a developer by choice. Focused in SharePoint & JavaScript.

  • Follow me on Twitter