Tech Tutorials Database
GeekArticles Database SQL Server
 

Exception Handling Advice for ASP.NET Web Applications

 
Author: 4guysfromrolla.com
Category: SQL Server
Comments (0)

<p><i>Exceptions</i> 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 input is not valid, an exception will be thrown. You can also raise exceptions from your own code by using the <code>Throw</code> keyword. </p><p> When an exception is thrown it is passed up the call stack. That is, if <code>MethodA</code> calls <code>MethodB</code>, and then <code>MethodB</code> raises an exception, <code>MethodA</code> is given the opportunity to execute code in response to the exception. Specifically, <code>MethodA</code> can do one of two things: it can <i>catch</i> the exception (using a <a ... <code>Catch</code></a> 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 <code>MethodA</code> not catching the exception or by <code>MethodA</code> re-throwing the exception - then the exception information will be passed up to the method that called <code>MethodA</code>. 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 <a Screen of Death</a>, by default). </p><p> 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 <code>Try</code> ... <code>Catch</code> 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! <br /><a More &gt;</a></p>

Read More...




Sponsored Links




Read Next: An Extensive Examination of LINQ: Grouping and Joining Data



 

 

Comments



Post Your Comment:

Your Name:*
e-mail ID:(required for notification)*
Image Verification: 
 
 Subscribe