Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

Embedded Error Handling in Generated Applications

25 Apr 2008 1  
The purpose of this article is to provide you with a useful tool for managing errors.

This article is in the Product Showcase section for our sponsors at CodeProject. These articles are intended to provide you with information on products and services that we consider useful and of value to developers.

Introduction

All of us need feedback to improve, and our applications are no different. If the users of our applications are experiencing issues, we need a reliable and verifiable method of recording and reporting these errors.

I created a simple table called ErrorLog in Microsoft SQL Server (easily transferable to Microsoft Access) and then referenced that table in my Iron Speed Designer application.

I then created a simple class called Support.vb to house my error log subroutine. I added the following code to this class:

However, after I created the function and started using it, I realized that I was going to have to declare my support object every time I wanted to use it on a particular page. That, I decided, was too tedious and time-consuming. Instead, I discovered that the right place to put common routines is the BaseApplicationPage class. There are base pages for table and record controls, as well. You can access the base pages here, under the Shared folder:

Using Microsoft Visual Studio, I opened the BaseApplicationPage.vb file and added the following code right after the Inherits declaration:

This makes my support object available across all Iron Speed Designer pages! Alas, the problem arose again when I wanted to access my support object from within an App_Code page. However, adding a single line of code into the Table and Record Base Pages solves the problem:

And our table control page...

Now, we are ready to use our new support object for error handling. You will have created the table in Microsoft SQL Server or Microsoft Access and referenced this table in Iron Speed Designer. You will have created the Support.vb file (or the C# equivalent) and placed it at the root of the App_Code folder.

Example use:

Note that I am also passing in the current function/subroutine, and the logged-in user ID as well.

You can also go another step further and add this into the Iron Speed Designer project templates so that all new applications have this code automatically included.

You can also copy your support.vb (or the equivalent support.cs) file into the following directory:

Placing your file here allows Iron Speed Designer to copy it into your new application folder. You will have to do this for every version of Iron Speed Designer that you install.

Conclusion

The original purpose of this article is to provide you with a useful tool for managing errors.

I hope you also realize that you can insert your favourite routines into your own Support.vb/Support.cs file. I have given you a nice, clean, and easy way to access functionality that is now accessible from every page and class in your application. What could be simpler?

You can download the SQL script and the support class by clicking on this link: Error Handling.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here