1. ERR object
There is no need to create an instance when using the err object, which means you can use it casually when you want to use it, just like a session.
There is no need to create an instance like Set conn=Server.CreateObject("ADODB.Connection") when using ADODB objects, which returns an error code.
However, Err!=Err.Number can be cleared with the Clear method to facilitate the next use. Its main method is a Description method, which returns a brief error description. Here is a very classic example:
Program code:
The code copy is 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:"%>
<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%>
After running, Err.Line is empty, why? Because the line method written in asp vb is not supported.
It is worth noting that when using the err object, On Error Resume Next must be added, and the exception that has passed the asperror object is thrown.
2. ERROR object
You can use the error object when linking the 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 number is a number.
Since Item is the default method, the writing method of Error(number) is equivalent to the previous one.
Below is a program. Used to enumerate Error objects:
Program code:
The code copy is 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 "Linking database failed<hr />"
for i =0 to conn.errors.count-1
response.write conn.errors.item(i)&"<hr />"
response.write Err.Description
next
else
response.write "Linking database successful"
end if
conn.close
%>
There is no difference between the err object, have you seen the comparison result? It is simple to use the err object directly.
It is generally recommended to use the asperror object during debugging (which is equivalent to not processing, and the error is the default information displayed on the web page).
If you rem the On Error Resume next line, you will use asperror to throw it by default.
When running officially, you can use the err object to do something unless you have special requirements.