Chapter 1 fault tolerance mechanism
Take the most popular ASP in China as an example. I don't know how many people will think of "fault" when I write code. In fact, when I encounter this kind of thing, I can't do it. Why, think about the initial meaning is that you can write the following code, see Example 1-1.
<% @ Language = VBScript%>
<% OPTION Explicit%>
<%
'Error filtering
ON Error ResMe next
................. (code slightly)%>
Example 1-1 Common code
The above code often appears in the hands of all the colleagues, don't have to say a middle place, I have completed the current mood, I can confess you, I wrote the two-year ASP page, most of them are this Way, constantly write, constantly change, heart intensity, now I don't want to turn back to rewrite the code. In fact, the idea of the most basic fault-tolerant mechanism is not to believe how many things can save you, and you must master the control in your own hands, it is necessary.
<% @ Language = VBScript%>
<% OPTION Explicit%>
<%
'=========================================
DIM NDEBUG_MSG
NDEBUG_MSG = True
IF ndebug_msg = True Then
'Error filtering
ON Error ResMe next
END IF
'=============== End ======================
............... (code slightly)
'Data Transaction --Start
IF err.number = 0 THEN
'~~~~~~~~~~~~~~~~~~~~~~~~~
'------------------------------
'-------------------------------------
Objconn.Begintrans
Objconn.execute (Objsql)
'~~~~~~ Commit the Transaction and Close The Database Connection
Objconn.committrans
Response.cachecontrol = "private"
Response.expires = -1
............... (code slightly)
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 fault tolerance mechanism code example
After reading the above code, you will find that there is no superb skill in it, the master may be more dismissed. But everyone may not be able to work like this.
[1-1] When writing a dynamic web page, be sure to consider fault tolerance mechanisms. If in ASP, you should refer to Example 1-2, and write a strong code.