コード例 #1
0
        public void TestNullMethodInfoInStack()
        {
            var frameMock = new Mock <System.Diagnostics.StackFrame>(null, 0, 0);

            frameMock.Setup(x => x.GetMethod()).Returns((MethodBase)null);

            Models.StackFrame stackFrame = new Models.StackFrame(frameMock.Object, 0);

            Assert.Equal("unknown", stackFrame.Assembly);
            Assert.Null(stackFrame.FileName);
            Assert.Equal("unknown", stackFrame.Method);
            Assert.Null(stackFrame.Line);
        }
コード例 #2
0
        private void HandleException(string ExceptionType, string Name, int Code, string Description, ref dbgExceptionAction ExceptionAction)
        {
            ExceptionEvent ex           = new ExceptionEvent();
            int            depthCounter = 0;

            EnvDTE90a.Debugger4 debugger = dte.Debugger as EnvDTE90a.Debugger4;

            if (debugger != null)
            {
                //not sure when the current thread could be NULL, but you never know with
                //the DTE.
                if (debugger.CurrentThread != null)
                {
                    foreach (EnvDTE.StackFrame dteFrame in debugger.CurrentThread.StackFrames)
                    {
                        EnvDTE90a.StackFrame2 frame      = (StackFrame2)dteFrame;
                        Models.StackFrame     modelFrame = new Models.StackFrame(frame);
                        modelFrame.Depth = depthCounter;
                        ex.StackFrames.Add(modelFrame);
                        depthCounter++;
                    }
                }
            }

            //the stuff inside this try will be null if there isn't an open document
            //window (rare, but possible)
            try
            {
                TextSelection debugSelection = dte.ActiveDocument.Selection;
                debugSelection.SelectLine();
                ex.LineContent  = debugSelection.Text;
                ex.LineNumber   = debugSelection.CurrentLine;
                ex.DocumentName = dte.ActiveDocument.Name;
            }
            catch (Exception)
            {
                ex.LineContent  = "";
                ex.LineNumber   = 0;
                ex.DocumentName = dte.Solution.FullName;
            }

            ex.EventDate            = DateTime.UtcNow;
            ex.ExceptionAction      = (int)ExceptionAction;
            ex.ExceptionCode        = Code;
            ex.ExceptionDescription = Description;
            ex.ExceptionName        = Name;
            ex.ExceptionType        = ExceptionType;
            ex.SolutionName         = dte.Solution.FullName;
            NotifyEventCreated(this, new EventCreatedArgs(ex));
        }