I am looking to develop an error handling strategy for a SharePoint solution that makes use of sandboxed webparts. I was initially looking at a general exception handling approach based on this article, but this doesn't work for sandboxed webparts. Once an unhandled exception has been thrown in the sandbox, the user code service appears to take control, so that the exception handling in the base web part isn't reached. Are there any established error handling approaches for sandboxed solutions?

Is anyone aware of a method of determining when an unhandled exception has been thrown in a sandboxed webpart, if only to change the displayed error message to a more user friendly message?

Thanks, MagicAndi.

2 Answers 2


Here's a link to an article that I found useful when writing an Office365 web part where debugging is virtually impossible.

MVPs for SharePoint 2010: Debugging Techniques for SharePoint Online Applications

  • 1
    Ian, a bit tangential to the error handling, but very useful all the same. Thanks & +1
    – Tangiest
    Apr 24, 2012 at 10:08

I've approached this problem by catching very broad exceptions (e.g. "Exception") in my own code. It's far from ideal, though, and Code Analysis whinges the first time I compile about catching Exception being a bad pattern.

Not a brilliant answer (essentially, "handle all exceptions") but it seems to work okay, and it was because I wanted a better error message for the user too.

  • Andy, thanks for your answer. +1 Poor form on Microsoft's part for forcing us to use this approach, assuming an alternative doesn't exist.
    – Tangiest
    Apr 24, 2012 at 10:00
  • 1
    Wait until you start looking at trying to log those exceptions in a Sandbox-only environment (e.g. Office 365). That's really fun...
    – Andy Burns
    Apr 24, 2012 at 10:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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