From 6788a3d70ce961613989144492a3fe5c51b3ac6c Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Thu, 27 Jul 2017 18:58:34 +0900 Subject: [PATCH 1/2] Always resolve the innermost exception to allow for easier debugging --- osu.Framework/Extensions/ExtensionMethods.cs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/osu.Framework/Extensions/ExtensionMethods.cs b/osu.Framework/Extensions/ExtensionMethods.cs index bd9a045ce4..40aa43ad96 100644 --- a/osu.Framework/Extensions/ExtensionMethods.cs +++ b/osu.Framework/Extensions/ExtensionMethods.cs @@ -153,7 +153,13 @@ public static string GetDescription(this Enum value) public static void ThrowIfFaulted(this Task task) { if (task.IsFaulted) - ExceptionDispatchInfo.Capture(task.Exception?.InnerException).Throw(); + { + Exception e = task.Exception; + while (e?.InnerException != null) + e = e.InnerException; + + ExceptionDispatchInfo.Capture(e).Throw(); + } } /// From 56968ced3ac354d8c3b8cc1b2e8fee3fe2fe9489 Mon Sep 17 00:00:00 2001 From: smoogipooo Date: Wed, 2 Aug 2017 16:18:36 +0930 Subject: [PATCH 2/2] Remove null-coalescing in favor of assertion. --- osu.Framework/Extensions/ExtensionMethods.cs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/osu.Framework/Extensions/ExtensionMethods.cs b/osu.Framework/Extensions/ExtensionMethods.cs index 40aa43ad96..e05e937bfa 100644 --- a/osu.Framework/Extensions/ExtensionMethods.cs +++ b/osu.Framework/Extensions/ExtensionMethods.cs @@ -4,6 +4,7 @@ using System; using System.Collections.Generic; using System.ComponentModel; +using System.Diagnostics; using System.Drawing; using System.IO; using System.Linq; @@ -155,7 +156,10 @@ public static void ThrowIfFaulted(this Task task) if (task.IsFaulted) { Exception e = task.Exception; - while (e?.InnerException != null) + + Debug.Assert(e != null); + + while (e.InnerException != null) e = e.InnerException; ExceptionDispatchInfo.Capture(e).Throw();