[. NET] Cerrstack easy to manage errors or exceptions

Source: Internet
Author: User

Option Explicit  onOption Strict  onImportsSystem.ReflectionImportsSystem.Diagnostics Public StructureErrinfo PublicNumber as Integer     PublicDescription as String     PublicComment as String     PublicClassName as String     PublicFuncName as String     Public Sub New(number as Integer, Description as String, Comment as String, ClassName as String, FuncName as String)         with Me            . number=Number . Description=Description. Comment=Comment. ClassName=ClassName. FuncName=FuncNameEnd  with    End Sub     Public Overrides FunctionToString () as String        DimMsg as String        IfCommentIsNot  Nothing  ThenMSG= ClassName &"::"& FuncName &"()"& VbCrLf & _                  "ERR"& Number.tostring &": "& Description & VbCrLf &_ vbCrLf&_ CommentElseMSG= ClassName &"::"& FuncName &"()"& VbCrLf & _                  "ERR"& Number.tostring &": "&DescriptionEnd If        ReturnMSGEnd Function     Public SubShowmsgbox ()MsgBox(Me. ToString (), msgboxstyle.critical,"Error"&number.tostring)End SubEnd Structure Public ClassCerrstackPrivateM_errstack as NewStack ( oferrinfo) Public FunctionPush (Errinfo asErrinfo) aserrinfo M_errstack.push (errinfo)ReturnErrinfoEnd Function     Public FunctionPush (OptionalComment as String= Nothing,OptionalStackframeindex as Integer=1) asErrinfoDimErrobj asErrObject =ERR ()ReturnPush (Errobj.number, Errobj.description, Comment, Stackframeindex +1)    End Function     Public FunctionPush (number as Integer, Description as String,OptionalComment as String= Nothing,OptionalStackframeindex as Integer=1) asErrinfoDimSTrace as NewStackTrace (True)        DimSframe asStackFrame =strace.getframe (Stackframeindex)DimTerror asErrinfoIfSframe is  Nothing  Thenterror=NewErrinfo (number, Description, Comment,"Unknownclass","Unknownmethod")        Else            DimTMethod asMethodBase =Sframe.getmethod () terror=Newerrinfo (number, Description, Comment, TMethod.ReflectedType.FullName, Tmethod.name)End IfM_errstack.push (Terror)ReturnterrorEnd Function     Public FunctionPush (ERR asErrObject,OptionalComment as String= Nothing,OptionalStackframeindex as Integer=1) asErrinfoReturnPush (Err.Number, Err.Description, Comment, Stackframeindex +1)    End Function     Public FunctionPush (Ex asException,OptionalComment as String= Nothing) aserrinfo M_errstack.push (NewErrinfo (ERR ().                                        Number, Ex.message, Comment,        Ex.TargetSite.ReflectedType.FullName, Ex.TargetSite.Name)) Returnm_errstack.last ()End Function     Public FunctionPush (Ex asException, number as Integer,OptionalComment as String= Nothing) aserrinfo M_errstack.push (Newerrinfo (number, ex.message, Comment, Ex.TargetSite.ReflectedType.FullName, Ex.targe Tsite.name))Returnm_errstack.last ()End Function     Public FunctionPop () asErrinfoIfM_errstack.count =0  Then Return  Nothing        ReturnM_errstack.pop ()End Function     Public ReadOnly  PropertyLast () asErrinfoGet            IfM_errstack.count =0  Then Return  Nothing            Returnm_errstack.last ()End Get    End Property     Public FunctionMsglasterrpop () asErrinfoIfM_errstack.count =0  Then Return  NothingMsglasterrpop=M_errstack.pop () Msglasterrpop.showmsgbox ( )End Function     Public FunctionMsglasterr () asErrinfoIfM_errstack.count =0  Then Return  NothingMsglasterr=M_errstack.peek () Msglasterr.showmsgbox ( )End Function     Public Overrides FunctionToString () as String        IfM_errstack.count =0  Then Return  Nothing        ReturnM_errstack.last (). ToString ()End FunctionEnd Class

[. NET] Cerrstack easy to manage errors or exceptions

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.