Exception Handling Advice for ASP.NET Web Applications

Posted by: 4GuysFromRolla.com Headlines, on 12 Aug 2009 | View original | Bookmarked: 0 time(s)

Exceptions are a construct in the .NET Framework that are (ideally) used to indicate an unexpected state in executing code. For example, when working with a database the underlying ADO.NET code that communicates with the database raises an exception if the database is offline or if the database reports an error when executing a query. Similarly, if you attempt to cast user input from one type to another - say from a string to an integer - but the user's input is not valid, an exception will be thrown. You can also raise exceptions from your own code by using the Throw keyword.

When an exception is thrown it is passed up the call stack. That is, if MethodA calls MethodB, and then MethodB raises an exception, MethodA is given the opportunity to execute code in response to the exception. Specifically, MethodA can do one of two things: it can catch the exception (using a Try ... Catch block) and execute code in response to the exception being throw; or it can ignore the exception and let it percolate up the call stack. If the exception is percolated up the call stack - either by MethodA not catching the exception or by MethodA re-throwing the exception - then the exception information will be passed up to the method that called MethodA. If no method in the call stack handles the exception then it will eventually reach the ASP.NET runtime, which will display the configured error page (the Yellow Screen of Death, by default).

In my experience as a consultant and trainer I have worked with dozens of companies and hundreds of developers and have seen a variety of techniques used for handling exceptions in ASP.NET applications. Some have never used Try ... Catch blocks; others surrounded the code in every method with one. Some logged exception details while others simply swallowed them. This article presents my views and advice on how best to handle exceptions in an ASP.NET application. Read on to learn more!
Read More >

Category: ASP.NET | Other Posts: View all posts by this blogger | Report as irrelevant | View bloggers stats | Views: 2268 | Hits: 80

Similar Posts

  • Introducing Recurring Appointments for Web.UI Scheduler ASP.NET AJAX more
  • ASP.NET 4 Web Server Here Shell Extension more
  • Announcing the WebsiteSpark Program more
  • Announcing the Microsoft AJAX CDN more
  • Intersoft Solutions Announces WebUI Studio 2009 Service Pack 1 more
  • Using the latest Web Testing Tools along with the latest RadControls more
  • Server vs. Client Empowered Web Applications more
  • Using SSL in your application more
  • Silverlight 3 Released more
  • Telerik Introduces Free Web Testing Framework for ASP.NET AJAX and Silverlight more

News Categories

.NET | Agile | Ajax | Architecture | ASP.NET | BizTalk | C# | Certification | Data | DataGrid | DataSet | Debugger | DotNetNuke | Events | GridView | IIS | Indigo | JavaScript | Mobile | Mono | Patterns and Practices | Performance | Podcast | Refactor | Regex | Security | Sharepoint | Silverlight | Smart Client Applications | Software | SQL | VB.NET | Visual Studio | W3 | WCF | WinFx | WPF | WSE | XAML | XLinq | XML | XSD