Abnormalities in DEVER.CN

zhaozj2021-02-16  53

Recalling the ASP era of definition from keywords or error codes, the exception handling mechanism in Java and .NET is now too much. First define an abnormal source Struct

Public struct erroritem {public string userip; // User IP public string page; // Error incorrect page public string resource; // Error source public string errorinfo; // error message public datetime errorTIME; / / error occurrence time}

Here are some main abnormal processing methods I use:

Public static void setError (Exception E) {system.Web.httpContext hc = system.Web.httpContext.current;

// Decompose the captured exception instance and process ErrorItem EI = New ErrorItem ();

Ei.Errorinfo = E.Message; ei.resource = E.Source; ei.page = hc.request.path; ei.userip = hc.request.userhostaddress.tostring (); ei.errorTime = DATETIME.NOW; SaveError EI, TRUE); // Call Error Processing Function}

Public Static Void SaveError (ERRORITEM Erritem, Bool IsView) {// Display Error Information Write Library for Display System.Web.httpContext HC = System.Web.httpContext.current; String Strsql = "Update Error Set -------------------------- ------ "SqlHandle.executeUpdateQuery (strsql)

Errorhandle EH = New ErrorHandle () // Determines if the log file exists, there is no new EH.isexistLog () // to write the error message to the log file XMLELEMENT XERRORELEMENT = XMLDoc.createElement ("Error");

eh.AddXmlAttribute (xErrorElement, "time", errItem.ErrorTime.ToString ()); eh.AddXmlAttribute (xErrorElement, "resource", errItem.Resource); eh.AddXmlAttribute (xErrorElement, "page", errItem.Page); eh .AddXmlAttribute (xErrorElement, "ip", errItem.UserIp); xErrorElement.InnerText = errItem.ErrorInfo; xmlRoot.AppendChild (xErrorElement); if (isView) {hc.Response.Redirect (DeverClass.getRoot ( "ErrorHandle.aspx") }}

// pop the error message with the pop-up window and automatically return the public static void pointror (String strerror) {system.web.httpContext hc = system.web.httpContext.current; hc.response.write ("