ASP error handling

Source: Internet
Author: User
Tags driver manager error code error handling odbc
Brief Introduction
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.
Error Type
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.
Handling error
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
Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

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: and provide relevant evidence. A staff member will contact you within 5 working days.