One, Err object
The Err object does not need to create an instance when used, which means that you use it as a session.
The Set Conn=server.createobject ("ADODB") does not need to be used like a ADODB object. Connection ") to create an instance that returns an error code.
However, Err!=err.number can be cleared with the clear method for the next use. It is mainly a description method, which returns a brief error description, here is a classic example:
Program code:
Copy Code code as follows:
<%@ 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 occurred:"%>
<title></title>
<body>
Error number: <%= err.number%><br/>
Error message: <%= err.description%><br/>
Error file: <%= err.source%><br/>
Error line: <%= err.line%><br/>
<%= ERR%>
</body>
<%end if%>
Run a look, Err.line is empty, why? Because the ASP VB written inside the line method is not supported.
It is worth noting that when you use the Err object, you must add on Error Resume Next, which is thrown over the exception of the ASPError object.
Second, the Error object
You can use the Error object when you link to a database:
Count property: Used to count the number of errors collections.
Item method: Used to specify a specific error, the syntax is Error.item (number), where numbers is one digit.
Because item is the default method, the writing of the error (number) is equivalent to that of the previous wording.
Here's a procedure. Used to enumerate the error objects:
Program code:
Copy Code code as follows:
<%
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 "link database failed For I =0 to conn.errors.count-1
Response.Write Conn.errors.item (i) & "Response.Write Err.Description
Next
Else
Response.Write "Linked database succeeded"
End If
Conn.close
%>
No difference and Err object, see comparison result? It is simple to use the Err object directly.
It is generally recommended that you use the ASPError object when debugging (which is equivalent to not processing, error is the default information displayed on the Web page),
is to put on Error Resume next this line REM, the default is thrown with ASPError.
When running, you can use the Err object to do something unless you have a special requirement.