Developer on Alibaba Coud: Build your first app with APIs, SDKs, and tutorials on the Alibaba Cloud. Read more ＞
ASP is so simple that many developers do not think about error handling. Error handling can make your application more reasonable. I have seen many commercial websites written in ASP, and most of them ignore error handling.
There are three main error types:
1. Compilation error:
This error is generally caused by the syntax of the code. The ASP program stops running due to a compilation error.
2. Running error:
This error occurs when you are preparing to run ASP. For example, if you try to assign a value to a variable, but it is beyond the permitted range of the variable.
3. Logic error:
Logical errors are the most difficult to find. Such errors are often structured errors that cannot be found by computers. This requires us to thoroughly check our code.
Because compilation errors are generally displayed along with logical errors, we only worry about running errors. It terminates ASP operations and leaves a pile of unfriendly text to users.
So how do we handle running errors?
Let's take a look at it. The only Error command provided by ASP --- On Error Resume Next (This reminds beginners that there is only the On Error Resume Next statement in ASP, and there is no On Error Resume Goto statement) if you do not use the On Error Resume Next statement, all running errors will occur, which is fatal, and an Error code will be displayed to the user, the ASP program stops.
The following 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 will be ignored and the program will automatically execute the Next statement. In this way, the program will be fully executed, and the user will not see the error information after the error. However, this is also a bad thing, that is, if the program is not executed as expected, it will be hard for you to find out what went wrong, so you have to handle the error where necessary.
In ASP, the best way to handle errors is to put code at the bottom of the program to handle errors. I also recommend using a buffer in every ASP program. In this way, if an error occurs, the page will stop and the page content will be cleared, so that the user will not see the error message, and there will be fewer complaints! The following is an example:
<% @ LANGUAGE = "VBScript" %>
<% Response. Buffer = True
"Set buffer to True
On Error Resume Next
"Start error handling
This article is an English version of an article which is originally in the Chinese language on aliyun.com and is provided for information purposes only. This website makes no representation or warranty of any kind, either expressed or implied, as to the accuracy, completeness ownership or
reliability of the article or any translations thereof. If you have any concerns or complaints relating to the article, please send an email, providing a detailed description of the concern or
complaint, to firstname.lastname@example.org. A staff member will contact you within 5 working days. Once verified, infringing content will be removed immediately.
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:
and provide relevant evidence. A staff member will contact you within 5 working days.