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.