I have been developing pages and web parts in SharePoint 2007/2010 over the past year. One of the things that I always include in my code is try / catch blocks to handle errors when an exception occurs. That way, if I have a web part that breaks down, I display an error message to the user in that particular web part, and not at the top of the page or the full page error. I am fine with this process, but I am looking for some input into my approach of using try / catch blocks (since I understand that there may be performance implications).
In general, I always use try / catch blocks when making database or web service calls. I even sometimes transfer my general C # code to try / catch blocks if there is complex logic that is implemented (and I could not check all the different cases). Sometimes I just have a little paranoia and we complete all the code in the entire web part with try / catch.
Can I get some feedback on using try / catch blocks for general C # development, and in particular, C # development in the SharePoint world? Also, I would like to understand how to effectively implement try / catch in my C # code when developing SharePoint solutions (is there a more global way to do this?)
Thanks in advance.
source share