first_page the funky knowledge base
personal notes from way, _way_ back and maybe today

MCAD/MCSD Notes: Chapter 6, Lesson 1; Using Exception Handling

Lesson 1: Using Exception Handling

The purpose of this lesson is to introduce "error" or "exception" handling in ASP.NET.

The three are: structured exception handling (SEH), error event procedures defined in the System.Web.UI.Page class and custom error pages declared in the @Page directive, its errorPage attribute.

The use of the term "nonmemory resources" sounds strange. What is more perhaps is to say that try/catch/finally blocks are useful when crossing "boundaries" or "layers" in an application.

The classic example for the above is closing a database connection when trying to connect to an external data source (and calling its Dispose() method).

The suggestion in the lesson is that exceptions can be used a primary form of communication instead of suggesting it for a secondary (or tertiary) form because of performance reasons. To the contrary, the lesson introduces the ApplicationException class to encourage us to define new exceptions based on this class.

These events are Page_Error, Global_Error and Application_Error. In the reality of Visual Studio .NET auto-generated code the Global_Error event procedure is not used.

The Server.GetLastError() and Server.ClearError() methods gets "the information" and clears the error, respectively. The code samples suggest that a useful design pattern is to get the last error, store it in a Session variable, clear the error and use Server.Transfer() to re-load the page throwing the error.

mod date: 2005-06-08T23:19:10.000Z