ASP three-tier architecture error Handling Class _ Application Tips

Source: Internet
Author: User
Starting from this section, we will give you a few ASP three general classes, which runs through the three-tier architecture I designed, is an extension of the ASP syntax, can improve the efficiency of many details processing, can be regarded as a little bit of the flavor of the framework.
This section describes the error handling class, the class name Con_error, which is initialized at the beginning of the code page, the instance name E, and the following E.add uses the instantiated object of the error class to operate.
Method Introduction:
E.add (ByVal verrormessage) logs an error and sets E.error = True. This method is invoked to record an error message when an error is found in a program that detects the legality of the username.
For example, when a user logs in with an incorrect password, call E.add ("Your account or password is incorrect"). At this time, Error object E is logged an error, the Error object's property E. Error=true. In subsequent operations, you can use this property of the Error object to determine.
For example:
A small window prompts an error after an error and returns to the previous page.
If E.error Then
E.alert_back "Please login again!" The role of ' Alert_back ' is described later.
End If
E.alert_back (ByVal Vmessage) uses JavaScript to eject an error balloon that displays all of the current error lists, and Vmessage in Alert_back (Vmessage) appears on the last line. Used to prompt the user for the steps to take after seeing this error message. and return to the previous page. The code for this method is posted and you will understand better:
Public Sub Alert_back (ByVal vmessage)
Strjsmessage = jsmessage & Vmessage ' jsmessage is used to store the list of errors in the E object, separated by \ n from each error.
%>
<script language= "JavaScript" >
<!--//
Alert ("<%=strjsmessage%>"); ' Pop-up prompts error box.
History.back (); ' Go back to the previous page
-->
</script>
<%
Response.End ' note here to stop the output, to avoid errors while the program continues to execute.
End Sub
E.alert_back method extends several similar effects of the method, as follows, the implementation of the process see additional source code:
E.alert (ByVal vmessage) only pops the error prompt box, does not return the previous page, and does not stop program execution.
E.alert_close (ByVal vmessage) pop-up error balloon, when the user clicks OK, closes the current window
E.ok_go (ByVal vmessage,byval vurl) pop-up message box, when the user clicks OK, jump to the Vurl page
E.go (ByVal Vurl) jump directly to Vurl page
The role of the above methods, we should be very familiar with, in fact, they are not limited to error handling.
E.clear empty the error message that is logged in the Error object, E.error = False
Because the E object is a global object, it may be invoked in a number of procedures. When you only need to count the errors in one module, you can start by calling this method and emptying the error in E.
The following are the packaging for the Response.Write, intended only for easy and fast use.
E.debug (ByVal vmessage) outputs debugging information. When the program is completed, there will be a lot of Response.Write output error debugging information, to be deleted and carefully look for. Use E. Debug specifically outputs debugging information, and when the program completes, you only need to search for E. Debug, you can find the location of all debugging error messages.
E.W (ByVal vmessage) output information. Just Response.Write simple packaging, in the program input E.W than the input Response.Write not know how much convenient, and always easy to write wrong.
e.br output a newline character, equivalent to response. Write "<br/>"
The following 4 are for Response.End packaging, just according to the operating habits, defined a few of the same functional methods:
E.pause = = Response.End
E.P = = Response.End
E.stop = = Response.End
E.end = = Response.End
There is also an attribute E. Message, output all error lists in E object
See the code for specific implementation details
Copy Code code 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 the 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 the 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
' Hu Jintao 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.