Skip to content

Commit

Permalink
Exception: display inner exceptions
Browse files Browse the repository at this point in the history
Closes #64
  • Loading branch information
fremag committed Feb 7, 2016
1 parent 0ab529c commit 6ed5e71
Show file tree
Hide file tree
Showing 5 changed files with 149 additions and 30 deletions.
19 changes: 18 additions & 1 deletion MemoDummy/ExceptionThreadScript.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using System.ComponentModel;
using System.Threading;
using System;
using System.Diagnostics;

namespace MemoDummy
{
public class ExceptionThreadScript : AbstractMemoScript
Expand All @@ -15,7 +17,22 @@ public override void Run()
{
for(int i=0; i < NbThreads; i++)
{
Thread thread = new Thread(() => { throw new IndexOutOfRangeException(); });
Thread thread = new Thread(() =>
{
int[] arrayInt = new int[5];
try
{
int x = arrayInt[arrayInt.Length];
if( x < 0)
{
Debug.WriteLine("Huh ?");
}
}
catch (Exception e)
{
throw new Exception("Something failed !", e);
}
});
thread.Name = "thread #" + i;
thread.Start();
}
Expand Down
1 change: 1 addition & 0 deletions MemoScope/MemoScope.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@
<Compile Include="Modules\DumpDiff\DiffColumn.cs">
<SubType>Component</SubType>
</Compile>
<Compile Include="Modules\ThreadException\ClrExceptionInformation.cs" />
<Compile Include="Modules\ThreadException\ThreadExceptionCommand.cs" />
<Compile Include="Modules\ThreadException\ThreadExceptionModule.cs">
<SubType>UserControl</SubType>
Expand Down
28 changes: 28 additions & 0 deletions MemoScope/Modules/ThreadException/ClrExceptionInformation.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using BrightIdeasSoftware;
using MemoScope.Core;
using MemoScope.Modules.StackTrace;
using Microsoft.Diagnostics.Runtime;
using System.Collections.Generic;
using System.Linq;

namespace MemoScope.Modules.ThreadException
{
public class ClrExceptionInformation
{
[OLVColumn(Width=450)]
public string TypeName { get; }
[OLVColumn(Width = 500)]
public string Message { get; }

public List<StackFrameInformation> StackFrames { get; }
private ClrException exception;

public ClrExceptionInformation(ClrDump clrDump, ClrException exception)
{
this.exception = exception;
Message = clrDump.Eval(() => exception.Message);
StackFrames = clrDump.Eval(() => exception.StackTrace.Select(frame => new StackFrameInformation(clrDump, frame))).ToList();
TypeName = exception.Type.Name;
}
}
}
93 changes: 73 additions & 20 deletions MemoScope/Modules/ThreadException/ThreadExceptionModule.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

38 changes: 29 additions & 9 deletions MemoScope/Modules/ThreadException/ThreadExceptionModule.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
using MemoScope.Core;
using MemoScope.Modules.StackTrace;
using Microsoft.Diagnostics.Runtime;
using System.Linq;
using System.Collections.Generic;
using MemoScope.Core.Helpers;

namespace MemoScope.Modules.ThreadException
{
public partial class ThreadExceptionModule : UIClrDumpModule
{
public ClrException Exception { get; private set; }
public List<ClrExceptionInformation> Exceptions { get; private set; }
private ClrThread ClrThread { get; set; }
private string Message { get; set; }
private List<StackFrameInformation> StackFrames { get; set; }
Expand All @@ -17,6 +17,7 @@ public ThreadExceptionModule()
{
InitializeComponent();
dlvStackTrace.InitColumns<StackFrameInformation>();
dlvExceptions.InitColumns<ClrExceptionInformation>();
}

public void Setup(ClrDump clrDump, ClrThread clrThread)
Expand All @@ -30,17 +31,36 @@ public void Setup(ClrDump clrDump, ClrThread clrThread)
public override void PostInit()
{
base.PostInit();
Summary = $"Id: {ClrThread.ManagedThreadId} : {Message}";
tbExceptionType.Text = Exception.Type.Name;
tbMessage.Text = Message;
dlvStackTrace.Objects = StackFrames;
Summary = $"Id: {ClrThread.ManagedThreadId} : {Exceptions.Count} exceptions";
}

public override void Init()
{
Exception = ClrDump.Eval(() => ClrThread.CurrentException);
Message = ClrDump.Eval(() => Exception.Message);
StackFrames = ClrDump.Eval( () => Exception.StackTrace.Select(frame => new StackFrameInformation(ClrDump, frame))).ToList();
Exceptions = new List<ClrExceptionInformation>();
ClrException exception = ClrDump.Eval(() => ClrThread.CurrentException);
while(exception != null)
{
Exceptions.Add(new ClrExceptionInformation(ClrDump, exception));
exception = ClrDump.Eval(() => exception.Inner);
}

dlvExceptions.Objects = Exceptions;
}

private void dlvExceptions_SelectedIndexChanged(object sender, System.EventArgs e)
{
var exception = dlvExceptions.SelectedObject<ClrExceptionInformation>();
if( exception != null)
{
Init(exception);
}
}

private void Init(ClrExceptionInformation exception)
{
tbExceptionType.Text = exception.TypeName;
tbMessage.Text = exception.Message;
dlvStackTrace.Objects = exception.StackFrames;
}
}
}

0 comments on commit 6ed5e71

Please sign in to comment.