Login | Register   
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


advertisement
 

Microsoft Exception Management Application Blocks

Good exception handling should be put into an application from the very beginning. The Microsoft Exception Management Application Block (EAAB) will allow you to write one line of code in all of your Catch blocks and this one line of code can be configured to call multiple classes to log errors in any way you see fit. The best part is you do not need to recompile your application; you simply have to provide a new DLL that contains these new exception classes.


advertisement
xceptions need to be handled in all applications. Having a consistent method of dealing with exceptions will make your application easier to debug. Recording exceptions into an SQL database or the Event log will make tracking and looking up exceptions much easier.

Microsoft created a generic exception handling class that you can use in any Catch block in addition to any regular error handling code that you might perform. The code in Listing 1 provides you an example of how to use the Exception Management Application Block EAAB:

The Publish method is a shared method of the ExceptionManager class. You pass to it the Exception object that you created in your Catch statement. By default the Publish method will call a routine that Microsoft has already written to put exception information into the Event Log. You may add entries to your application configuration file to override this default behavior. You'll learn how to override the default later in this article.

Benefits of the Exception Manager Class
You can get many benefits from using the Exception Management Application Block.

  • Consistent interface for handling errors
  • One routine that you need to work with
  • Can place exception publishers into separate component
  • Easily add new exception publishers
  • Add publishers without changing any code in your application
Getting and Installing the Exception Manager
You can download the Microsoft Exception Management Application Block for Free!
To get the Exception Manager components you need to download the MSI installation package from Microsoft's Web site.

After you download the MSI file, double-click it to install the EAAB. The installation creates a folder on your hard drive, installs the samples, the source code for the component, the help files, and creates an item within your Programs folder so you can access the samples and help from your Start menu. Since this is a .NET component there are no registry entries or anything else that is installed that will affect your Windows system. (See Sidebar: Other Application Blocks)

Compile the EAAB
Before you can use the EAAB you need to compile the source code. Microsoft does not supply a DLL with the installation. Open your Start | Programs menu and find the Microsoft Application Blocks for .NET | Exception Management | Source Code (VB) menu. Choose the Exception Management Application Block source code and VS.NET will load the VB.NET source code for you to compile. (You could also choose the C# source code as well, since Microsoft supplies both.) VB.NET loads two projects within this solution. One project supplies the interfaces that the classes will implement within the other project, and that you will implement when you create custom publishers. The other project contains several classes that help implement the Exception Management Application Block.

Select Build | Build Solution from the VS.NET menu and a Bin folder will be created under the folder where you installed the EAAB. Within this BIN folder you will find two DLLs:

Microsoft.ApplicationBlocks. _ ExceptionManagement.dll Microsoft.ApplicationBlocks. _ ExceptionManagement.Interfaces.dll


You will need to include both of these as references within any project in which you wish to use the EAAB.



Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap