Dynamic | fault-tolerant | Web page with the most popular ASP as an example, I do not know how many people will be in the code to think of the "fault tolerance" concept, in fact, when I encountered such a thing, but also nothing. Why, think about the original idea of thinking that writing code like this would be a fault-tolerant, as shown in example 1-1.
<%@ Language=vbscript%>
<%option explicit%>
<%
' ERROR filtering
On Error Resume Next
............... (Code slightly)
%>
Example 1-1 Common code glimpse
The above code often appears in the hands of fellow colleagues, needless to say the reason, I finished can understand you now mood, I can tell you frankly, I wrote two years of ASP page, most of this way, constantly write, constantly change, burnout, now do not want to go back to rewrite their own code. In fact, the idea of the most basic fault-tolerant mechanism is not to believe that the program can save you much, it is necessary to control the power in their own hands.
<%@ 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 slightly)
' 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 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-tolerant mechanism code example
Read the above code, you will find that there is no superb skills in the inside, the master may be dismissive. But you may not be able to do this when writing code.
"1-1" When writing dynamic Web pages, must consider fault-tolerant mechanism, such as in the ASP, you should refer to example 1-2, write robust code.