Several general processing methods of ASP errors

Source: Internet
Author: User
Tags driver manager error code error handling odbc
Simple Introduction
ASP is so simple that many developers don't think about error handling, and handling errors correctly can make your application more reasonable. I've seen many commercial Web sites written in ASP, most of them ignoring error handling.
There are three major types of errors:
Compilation Error:
This error is generally a grammatical problem of the code.
The resignation ASP is stopped because of a compile error.
Run error
This error occurs when you are ready to run the ASP.
For example, if you try to assign a value to a variable, it exceeds the allowable range for that variable.
Logical error
Logic errors are the hardest to find, and they are often a structural error that computers cannot find.
This requires us to thoroughly examine our code.
Because compilation errors usually occur with logical errors, they are generally displayed, so we are worried about just running errors. It terminates the operation of the ASP and throws a bunch of unfriendly text to the user.
 
So how do we deal with running errors!? Let's take a look at the error command that the ASP only provides to us---on Resume next (here's a reminder for beginners, in ASP, only on Error Resume Next statement, no On Error Resume goto statement) If you don't use on Error Resume Next statement, all running errors will occur, this is fatal, then there will be an error code "show" to the user, and the ASP program will also stop.
Here is an error code:

Microsoft OLE DB Provider for ODBC Drivers error 80004005
[Microsoft] [ODBC Driver Manager] Data source name not found and no default driver specified
/test.asp, line 60


When we use the On Error Resume Next statement at the top of the program, all errors are ignored and the program automatically executes the next statement. The program will execute completely, and the user will not see the error message after the error. But there's also a downside, which is that if the program doesn't execute as you think, it's hard to find out exactly where the problem is, so you have to deal with the error where necessary.

Handling Errors
In ASP, the best way to handle errors is to put code at the bottom of the program to handle the error. I also recommend using buffers in every ASP program. In this case, if the error occurs, the page will stop, the page content will also be cleared, so that users will not see the error message, you have less complaints! Here is an example:
<%@ language= "VBScript"%>
<% ' Set buffer to True
Response.Buffer = True
' Start error handling
On Error Resume Next
%>
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.