Chapter 1 fault tolerance mechanism <high quality dynamic web page technical programming guide (draft)>

Source: Internet
Author: User
Chapter 1 fault tolerance mechanism
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.

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.