Summary of err and error in ASP

Source: Internet
Author: User
ERR Object

When the ERR Object is used, you do not need to create an instance. That is to say, you can use it whenever you use it. Just like session, you do not need to set conn = server when using the ADODB object. createobject ("ADODB. connection ") to create an instance, it returns an error Code , But err! = Err. number, which can be cleared using the clear method to facilitate next use. it mainly refers to the description method and returns a brief error description. Here is a classic example: program code <% @ Language = "VBScript" %>
<% Response. Buffer = true
On Error resume next
%>
<%
S = "sa"
Response. Write (INT (s ))
If err. Number <> 0 then
Response. Clear
Response. Write "error:" %>
<HTML>
<Head>
<Title> </title>
</Head>
<Body>
Error number: <% = err. Number %> <br/>
Error message: <% = err. Description %> <br/>
Error file: <% = err. Source %> <br/>
Error line: <% = err. Line %> <br/>
<% = Err %>
</Body>
</Html>
<% End if %>

Run the command to check whether the queue and err. Line are empty. Why? The line method in asp vb is not supported. It is worth noting that the on error resume next must be added when the ERR Object is used, and the exception that crossed the asperror object is thrown.

Error object
When connecting to the database, you can use the error object: Count attribute to count the number of errors sets. The item method is used to specify a specific error. The syntax is error. item (number), where number is a number. Because item is the default method, the error (number) method is equivalent to the previous method. Below is a sectionProgram. Used to list error objects: program code <%
On Error resume next
Set conn = server. Createobject ("ADODB. Connection ")
Dim I, your_databasepath: your_databasepath = "No. mdb"
Connstr = "provider = Microsoft. Jet. oledb.4.0; Data Source =" & server. mappath (your_databasepath )&""
Conn. Open connstr
If conn. errors. Count <> 0 then
Response. Write "failed to connect to database <HR/>"
For I = 0 to conn. errors. Count-1
Response. Write conn. errors. Item (I) & "<HR>"
Response. Write err. Description
Next
Else
Response. Write "succeeded in connecting to the Database"
End if
Conn. Close
%>

No difference with the ERR Object. Have you seen the comparison result? It's easy to use the ERR Object directly.

generally, we recommend that you use the asperror object during debugging (this is equivalent to not processing, and the error is the default information displayed on the webpage), that is, the on error resume next line of REM, asperror is thrown by default. you can use the ERR Object To Do Something unless otherwise required.

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.