ASP three-tier architecture Error handling

Source: Internet
Author: User

Starting from this section, I will introduce you to several three common ASP classes. It runs through the three-tier architecture I designed and extends the ASP syntax, it can improve the processing efficiency of many details, but it can be regarded as a little bit of framework.
This section describes the error handling class. The class name Con_Error is initialized at the beginning of the code page. The instance name is e, and the following e. add is used to operate on the instantiated object of the error class.
Method Introduction:
E. Add (ByVal vErrorMessage) records an Error and sets e. Error = true. This method is called to record an Error message when an Error is found in the User Name check validity and other places.
For example, if the user's logon password is incorrect, call e. add ("your account or password is incorrect "). at this time, an error is recorded in error Object e. error = true. in subsequent operations, you can use this attribute of the error object for judgment.
For example:
When an error occurs, a small window prompts an error and returns to the previous page.
If e. Error then
E. Alert_Back "Please log on again! "The Role of 'alert _ Back is described later.
End if
E. alert_Back (ByVal vMessage) uses Javascript to pop up an error prompt box, displaying the list of all current errors. The vMessage in Alert_Back (vMessage) is displayed on the last line, the steps required to prompt the user to see this error message. and return to the previous page. the code of this method will be better understood:
Public Sub Alert_Back (ByVal vMessage)
StrJSMessage = JSMessage & vMessage 'jsmessage is used to store the error list in the e object. Each error is separated by \ n.
%>
<Script language = "javascript">
<! --//
Alert ("<% = strJSMessage %>"); 'the error message box is displayed.
History. back (); 'returns the previous page
// -->
</Script>
<%
Response. end' note that the output should be stopped to avoid errors while the program continues to execute.
End Sub
E. The Alert_Back method extends several methods with similar effects. For the implementation process, see the additional source code:
E. Alert (ByVal vMessage) only prompts the error prompt box, does not return to the previous page, or stops program execution.
E. Alert_Close (ByVal vMessage) the error prompt box is displayed. When you click OK, close the current window.
E. OK _Go (ByVal vMessage, ByVal vURL) dialog box appears. When you click OK, You will be redirected to the vURL page.
E. Go (ByVal vURL) directly jumps to the vURL page
We should be familiar with the functions of the above methods. In fact, they are not limited to error handling.
E. Clear clears the Error information recorded in the Error object. e. Error = false
Because the e object is a global object, it may be called in many processes. when you only need to count errors in a module, you can call this method to clear errors in e.
The following are the packages for Response. Write, which are used for convenience and speed.
E. debug (ByVal vMessage) Outputs debugging information. when the program is completed, many of them use Response. the error debugging information output by write must be deleted and detailed. use e. debug outputs debugging information. When the program is complete, you only need to search for e. debug to locate all debugging error messages.
E. w (ByVal vMessage) output information. only Response. write simple packaging, input e. w than input Response. write does not know how convenient it is, and it is always easy to write errors.
E. BR outputs a line break, equivalent to response. Write "<BR/>"
The following four methods are used to package Response. End. They are just defined according to the operation habits:
E. Pause = Response. End
E. P = Response. End
E. Stop = Response. End
E. End = Response. End
There is also an attribute e. Message that outputs a list Of all errors in the e object.
For detailed implementation details, see the code Copy codeThe Code is as follows: Class Con_Error
Private blnError
Private strMessage
Private strJSMessage
Private Sub Class_initialize ()
BlnError = false
StrMessage = ""
End Sub
Private Sub Class_Terminate ()
End Sub
'================================================ ========================================================== ===
'Property
'================================================ ========================================================== ===
'Message:
Public Property Let Message (ByVal value)
StrMessage = value
End Property
Public Property Get Message ()
Message = strMessage
End Property
'Error number
Public Property Get Error ()
Error = blnError
End Property
'Jsmessage: show in messagebox
Private Property Get JSMessage ()
StrJSMessage = Replace (strMessage, "<br>", "\ n ")
StrJSMessage = Replace (strJSMessage, vbCrLf ,"")
JSMessage = strJSMessage
End Property
'================================================ ========================================================== ===
'Method
'================================================ ========================================================== ===
'Add: Add an Error message
Public Sub Add (ByVal vMessage)
BlnError = true
StrMessage = strMessage & vMessage & "<br>"
End Sub
Public Sub Clear
BlnError = false
StrMessage = ""
End Sub
'Alert
Public Sub Alert (ByVal vMessage)
StrJSMessage = JSMessage & vMessage
%>
<Script language = "javascript">
<! --//
Alert ("<% = strJSMessage %> ");
// -->
</Script>
<%
End Sub
'Alert_back: alert and back
Public Sub Alert_Back (ByVal vMessage)
StrJSMessage = JSMessage & vMessage
%>
<Script language = "javascript">
<! --//
Alert ("<% = strJSMessage %> ");
History. back ();
// -->
</Script>
<%
Response. end
End Sub
'Alert_close: alert and close
Public Sub Alert_Close (ByVal vMessage)
StrJSMessage = JSMessage & vMessage
%>
<Script language = "javascript">
<! --//
Alert ("<% = strJSMessage %> ");
Window. opener = null;
Window. close ();
// -->
</Script>
<%
Response. end
End Sub
'*************************************** ******
'Debug: response. write, use it to delete Debug message easily, just seach "e. debug" from files
'*************************************** ******
Public Sub OK _Go (ByVal vMessage, ByVal vURL)
StrJSMessage = JSMessage & vMessage
%>
<Script language = "javascript">
<! --//
Alert ("<% = strJSMessage %> ");
Location. href = '<% = vURL %> ';
// -->
</Script>
<%
Response. end
End Sub
Public Sub Go (ByVal vURL)
Response. Redirect vURL
Response. end
End Sub
'*************************************** ******
'Debug: response. write, use it to delete Debug message easily, just seach "e. debug" from files
'*************************************** ******
Public Sub Debug (ByVal vMessage)
Response. Write vMessage
Response. flush
End Sub
'***** W: write
Public Sub W (ByVal vMessage)
Response. Write vMessage
End Sub
'***** BR: write <br>
Public Sub Br
Response. Write "<BR/>"
End Sub
'*************************************** ******
'Pause: response. end, mark debug info clearly
'*************************************** ******
Public Sub Pause
Response. end
End Sub
Public Sub P
Response. end
End Sub
Public Sub [Stop]
Response. end
End Sub
Public Sub [end]
Response. end
End Sub
End Class

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.