While building custom SharePoint webparts one of the hardest things is usually debugging (unless you know how to set it up correctly).
At first I would just attach to the IIS worker process in Visual Studio to do all my debugging. To do this all you have to do is click Debug/Attach to Process… in Visual Studio. Then find the SharePoint process, it is usually the w3wp.exe process that is running under your SharePoint admin account. After doing that SharePoint will pick up breakpoints in your code.
While this is good, it can take a little bit of time and it doesn’t help to get errors from your testing team or environments you don’t have debug authority over. However, SharePoint does have a way to show errors (including call stacks) right on the SharePoint page. Usually, when there is a bug in SharePoint it redirects you to a generic error page without any information on what happened. And, if your lucky, you might get some error information in your logs(but not always :).
But, with a few web.config modifications you can get this error information to show up, on your webpage. First change the “CallStack” property to “true” in the “SafeMode” tag. Next change the “customErrors” tag “mode” to “off”. Now your SharePoint error page will show debug information.