Login | Register   
LinkedIn
Google+
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 : Page 4

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
Publishing Errors via E-mail
Publishing exceptions by sending them to a specific e-mail address is very similar to publishing them to a database. You create an entry in your configuration file that identifies which class to call and then you will write that class and implement the Publish method according to the IExceptionPublisher interface. Listing 9 shows an example of a class that will send any errors via e-mail.

The code in the Publish method of the EMeMail class is passed the configuration information in the configSettings object. This object contains the name/value pairs that come from the configuration file for your application. If you remember from the beginning of this article, you added the attributes FromEMail, ToEMail and Subject to the

element for the Email publisher as shown below.

<!-- Publishes to EMail --> <publisher mode="on" assembly="ErrorCommon" type="ErrorCommon.EMeMail" FromEMail="Webmaster@pdsa.com" ToEMail="PSheriff@pdsa.com" Subject="Exception from VB.NET Application" />

The Publish method uses these attributes, the form name and application name passed in the additional info, and the exception object information to send an e-mail to the appropriate person about the exception that has occurred in this application.

Summary
Good exception tracking can really help developers after the application is deployed. Many users neglect to report errors back to the programmer. By creating a logging mechanism programmers can look up any and all errors without relying on the user. Microsoft supplies the Exception Management Application Block as a free download on their Web site. The ExceptionManager class will publish exceptions to the Event Log by default. Using a combination of web.config entries and your own custom classes that define a specific interface you can create your own publishers in a matter of minutes.



Paul D. Sheriff is the President of PDSA, Inc. (www.pdsa.com), a Microsoft Managed Partner company in Southern California. Paul is the MSDN Regional Director for Southern California, and has three books on .NET. The first book, ASP.NET Developer's Jumpstart, from Addison-Wesley was co-written with Ken Getz. His other two books are eBooks and can be purchased from the PDSA Web site. .
Comment and Contribute

 

 

 

 

 


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

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date