Attribute explanation and usage of ERR and Error object in ASP example _asp programming

Source: Internet
Author: User

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.

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.