Skip to content

Commit 6ed5e71

Browse files
author
fremag
committed
Exception: display inner exceptions
Closes #64
1 parent 0ab529c commit 6ed5e71

File tree

5 files changed

+149
-30
lines changed

5 files changed

+149
-30
lines changed

MemoDummy/ExceptionThreadScript.cs

+18-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
using System.ComponentModel;
22
using System.Threading;
33
using System;
4+
using System.Diagnostics;
5+
46
namespace MemoDummy
57
{
68
public class ExceptionThreadScript : AbstractMemoScript
@@ -15,7 +17,22 @@ public override void Run()
1517
{
1618
for(int i=0; i < NbThreads; i++)
1719
{
18-
Thread thread = new Thread(() => { throw new IndexOutOfRangeException(); });
20+
Thread thread = new Thread(() =>
21+
{
22+
int[] arrayInt = new int[5];
23+
try
24+
{
25+
int x = arrayInt[arrayInt.Length];
26+
if( x < 0)
27+
{
28+
Debug.WriteLine("Huh ?");
29+
}
30+
}
31+
catch (Exception e)
32+
{
33+
throw new Exception("Something failed !", e);
34+
}
35+
});
1936
thread.Name = "thread #" + i;
2037
thread.Start();
2138
}

MemoScope/MemoScope.csproj

+1
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,7 @@
191191
<Compile Include="Modules\DumpDiff\DiffColumn.cs">
192192
<SubType>Component</SubType>
193193
</Compile>
194+
<Compile Include="Modules\ThreadException\ClrExceptionInformation.cs" />
194195
<Compile Include="Modules\ThreadException\ThreadExceptionCommand.cs" />
195196
<Compile Include="Modules\ThreadException\ThreadExceptionModule.cs">
196197
<SubType>UserControl</SubType>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
using BrightIdeasSoftware;
2+
using MemoScope.Core;
3+
using MemoScope.Modules.StackTrace;
4+
using Microsoft.Diagnostics.Runtime;
5+
using System.Collections.Generic;
6+
using System.Linq;
7+
8+
namespace MemoScope.Modules.ThreadException
9+
{
10+
public class ClrExceptionInformation
11+
{
12+
[OLVColumn(Width=450)]
13+
public string TypeName { get; }
14+
[OLVColumn(Width = 500)]
15+
public string Message { get; }
16+
17+
public List<StackFrameInformation> StackFrames { get; }
18+
private ClrException exception;
19+
20+
public ClrExceptionInformation(ClrDump clrDump, ClrException exception)
21+
{
22+
this.exception = exception;
23+
Message = clrDump.Eval(() => exception.Message);
24+
StackFrames = clrDump.Eval(() => exception.StackTrace.Select(frame => new StackFrameInformation(clrDump, frame))).ToList();
25+
TypeName = exception.Type.Name;
26+
}
27+
}
28+
}

MemoScope/Modules/ThreadException/ThreadExceptionModule.Designer.cs

+73-20
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
using MemoScope.Core;
22
using MemoScope.Modules.StackTrace;
33
using Microsoft.Diagnostics.Runtime;
4-
using System.Linq;
54
using System.Collections.Generic;
5+
using MemoScope.Core.Helpers;
66

77
namespace MemoScope.Modules.ThreadException
88
{
99
public partial class ThreadExceptionModule : UIClrDumpModule
1010
{
11-
public ClrException Exception { get; private set; }
11+
public List<ClrExceptionInformation> Exceptions { get; private set; }
1212
private ClrThread ClrThread { get; set; }
1313
private string Message { get; set; }
1414
private List<StackFrameInformation> StackFrames { get; set; }
@@ -17,6 +17,7 @@ public ThreadExceptionModule()
1717
{
1818
InitializeComponent();
1919
dlvStackTrace.InitColumns<StackFrameInformation>();
20+
dlvExceptions.InitColumns<ClrExceptionInformation>();
2021
}
2122

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

3937
public override void Init()
4038
{
41-
Exception = ClrDump.Eval(() => ClrThread.CurrentException);
42-
Message = ClrDump.Eval(() => Exception.Message);
43-
StackFrames = ClrDump.Eval( () => Exception.StackTrace.Select(frame => new StackFrameInformation(ClrDump, frame))).ToList();
39+
Exceptions = new List<ClrExceptionInformation>();
40+
ClrException exception = ClrDump.Eval(() => ClrThread.CurrentException);
41+
while(exception != null)
42+
{
43+
Exceptions.Add(new ClrExceptionInformation(ClrDump, exception));
44+
exception = ClrDump.Eval(() => exception.Inner);
45+
}
46+
47+
dlvExceptions.Objects = Exceptions;
48+
}
49+
50+
private void dlvExceptions_SelectedIndexChanged(object sender, System.EventArgs e)
51+
{
52+
var exception = dlvExceptions.SelectedObject<ClrExceptionInformation>();
53+
if( exception != null)
54+
{
55+
Init(exception);
56+
}
57+
}
58+
59+
private void Init(ClrExceptionInformation exception)
60+
{
61+
tbExceptionType.Text = exception.TypeName;
62+
tbMessage.Text = exception.Message;
63+
dlvStackTrace.Objects = exception.StackFrames;
4464
}
4565
}
4666
}

0 commit comments

Comments
 (0)