Click here to Skip to main content
15,892,005 members
Articles / Web Development / ASP.NET
Article

Embedded Error Handling in Generated Applications

25 Apr 2008CPOL2 min read 10.5K   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.

Image 1

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

Image 2

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:

Image 3

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

Image 4

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:

Image 5

And our table control page...

Image 6

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:

Image 7

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.

Image 8

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

Image 9

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, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Web Developer Milestone Software Inc.
Canada Canada
Miles is a senior consultant and principal of Milestone Software and has been providing his clients with the right solutions for over twenty five years. He was the first to offer formal Iron Speed Designer training, and has been coaching and mentoring Iron Speed users since 2005. Miles is an Iron Speed MVP who loves to help clients finish their projects. He is an experienced data modeler who believes in strong database architecture and a best practices approach to software development.

For more information, have a look here:

http://www.ironspeedmvp.com
http://www.ironspeed.com/mvp/MVPMilesGibson.aspx

Comments and Discussions

 
-- There are no messages in this forum --