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=("") when using ADODB objects, it returns an error code.
However, Err!= 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:
< %@ LANGUAGE="VBscript" %> < % = True On Error Resume Next %> < % s="sa" (Int(s)) If <> 0 Then "An error occurred:"%> <html> <head> <title></title> </head> <body> mistake Number: < %= %><br /> mistake信息: < %= %><br /> Error file: < %= %><br /> An error occurred: < %= %><br /> < %= Err %> </body> </html> < %End If%>
After running, it is empty, why? Because the line method written in Asp's 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 asp error 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 (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:
<% On Error Resume next Set conn=("") Dim i,your_databasepath:your_databasepath="" connstr="Provider=.4.0;Data Source="&(your_databasepath)&"" connstr if <>0 then "Failed to link the database<hr />" for i =0 to -1 (i)&"<hr />" next else "Linking database successful" end if %>
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 (it 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.