locked
Best practise in handling exception for a custom webpart RRS feed

  • Question

  • Is there any best practise in handling exception in the event there is some error to the custom webpart?

    Thanks in advance.
    • Moved by Mike Walsh FIN Sunday, June 21, 2009 9:13 AM prog q (From:SharePoint - General Question and Answers and Discussion)
    Sunday, June 21, 2009 3:26 AM

Answers

  •  

    Hi,

    Hope those two posts help you:

    http://www.sharepointsecurity.com/blog/sharepoint/sharepoint-2007-development/webpart-exception-error-handling/ (WebPart Exception / Error Handling)

    http://www.codeproject.com/KB/sharepoint/Errorhandling_in_Webparts.aspx (Error handling in Webparts for SharePoint 2007)

     


    Mahdi Abdulhamid - MCTS http://www.devexpert.net

     

    • Proposed as answer by Moss-dever Tuesday, June 23, 2009 3:58 AM
    • Marked as answer by Aaron Han - MSFT Thursday, June 25, 2009 10:18 AM
    Sunday, June 21, 2009 8:46 AM
  • To add more detail to the responses above, I would:

    * Catch specific exceptions, then catch general exception
    * Display a friendly error message to the end user, in a label rather than displaying the SharePoint error page.
    * Handle your own exceptions, don't rely on SharePoint or another layer to handle expections for you.
    * Log the error in a central place and be consistent.  You can log errors to the event view or to the SharePoint Trace Log, or even a SharePoint list.  Just make sure its consistent and the right people can access it.  For example: with hosted solutions don't log to the SharePoint Trace Log or Event Viewer if you don't have access to it.  SharePoint list is a flexible option as you can use alerts to be notified of any error messages.
    * Try to capture any inputs or helpful diagnostic information so the error can be reproduced easily.

    Hope this helps

    Dave


    My SharePoint Blog - http://www.davehunter.co.uk/blog
    • Edited by Dave Hunter Monday, June 22, 2009 1:31 PM
    • Proposed as answer by Moss-dever Tuesday, June 23, 2009 3:58 AM
    • Marked as answer by Aaron Han - MSFT Thursday, June 25, 2009 10:18 AM
    Monday, June 22, 2009 12:52 PM

All replies