Correctly handle Fault Tolerance Mechanisms in ASP dynamic web pages

Source: Internet
Author: User

Taking the most popular ASP in China as an example, I don't know how many people will think of the concept of "Fault Tolerance" when writing code. In fact, when I encounter this kind of thing, it is also gone. Why? In the first place, I thought that writing the following code would be fault-tolerant. See example 1-1.
<% @ Language = VBScript %>
<% Option explicit %>
<%
'Error Filtering
On Error resume next
............... (Code omitted)
%>
Example 1-1 Common Code

The above code often appears in the hands of colleagues. I don't have to say a reason. I can understand your current mood. I can honestly say that, I have been writing ASP Web pages for two years. Most of them are in this way. I am constantly writing, changing, and submitting documents. Now I don't want to rewrite my own code. In fact, the most basic idea of the fault tolerance mechanism is not to trust how much the program can save for you, but to put control in your own hands. This is necessary.
<% @ Language = VBScript %>
<% Option explicit %>
<%
'================================================ =
Dim ndebug_msg
Ndebug_msg = true
If ndebug_msg = true then
'Error Filtering
On Error resume next
End if
'==================== End ===============================
............... (Code omitted)
'Data transaction processing-start
If err. Number = 0 then
'~~~~~ Open Database and begin transaction ~~~~~~~~~~~~~~~~~~~~
'------------------------------
'-------------------------------------
Objconn. begintrans
Objconn. Execute (objsql)
'~~~~~~ Commit the transaction and close the database connection
Objconn. committrans
Response. cachecontrol = "private"
Response. expires =-1
............... (Code omitted)
Else
'~~~~~ Rollback transactions and close objects
Objconn. rollbacktrans
'~~~~~ Raise Errors for ASP page
'Err. Raise err. Number, Err. Source, Err. Description
'Err. Clear
Response. Write "Description = (" & err. Number & "), (" & err. Description &")"
End if
'================ End files ========================================
%>

Example 1-2 complete error tolerance mechanism code example

After reading the above Code, you will find that there is no superB skill in it, and the experts may be dismissive. But you may not be able to do this when writing code.

[1-1] When writing dynamic web pages, you must consider the fault tolerance mechanism. For example, in ASP, you should refer to Example 1-2 to write robust code.

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.