Debugging & Efficiency in ASP
All programmers have mistakes in their scripts, it's impossible not to make some. There are several methods to detect and correct them. Microsoft offers a Script Debugger which can be a useful tool, particularly if you've used Microsoft technology all over (ASP and Access, and the JScript or VB languages).
Note that you have to enable the Debugger, before you can start using it. It will allow you to do different things, such as to run only parts of your code, to see if they're working, or to check the evolution of the variables as the script develops. With this tool you can insert breakpoints, which will stop your script from running at a certain moment, so you can have a closer look of how it behaved until then. You cannot make modifications in your script directly in the Debugger, you need to open the editor in which you wrote the code lines initially, and to modify your code where it is.
When your code is not working, you should check for syntax mistakes, as they are the most common, and the most annoying. It can be anything, a typing mistake, a misspelled word, missing quotation marks, and so on. In most cases, if your script doesn't run at all, then you probably have a very simple, basic mistake.
If your script seems to runs smoothly, but its results are incorrect, then you probably have a logic mistake. These are a little trickier to handle, and it often means that your approach was mistaken from the very beginning, and you will have a lot of modifications to make. Check your "loops" and "ifs", one of the most common logical mistakes is found in the conditions for the "ifs".
There are also run-time errors. This means that the script found an operation which is impossible to perform, and so it has to stop. You need to correct that error before your script continues working.
IIS5 also offers an object called ASPError. You can only use it with the method called Server.GetLastError(), and it will give you data about the problems encountered with the script. Its properties include Source (which returns the actual code line which caused the error), File (the name of the file that generated the error), Description (yes, this is actually a brief description of the error), Column (the column position within the file that generated the error) and Category (which attempts to tell you what type of error it was, if it was caused by an ASP script or by an object, and so on). If the error is ASP-related, you can also use the property ASPDescription, which returns a more detailed description of the error.
The ASPError object can help you set up a centralized way of dealing with errors. Sometimes you can't be there to correct the error, or maybe you want the script to send you an e-mail with the description of the error. This tool is very useful when you are dealing with large scripts and when you want more than one person to handle the errors. You can also use it to create some custom-made, user friendly error messages.
No comments yet. Be the first.
Leave a reply


Bas de Baar, blogging as "The Project Shrink", is taking his message to the International Project Management community with a vengeance: "Projects Are About Humans. Now Deal With That!" ...