From dfcaae90c4f78bfce97e26625579b101e63302c4 Mon Sep 17 00:00:00 2001 From: Haven1433 Date: Sat, 10 Sep 2022 21:30:28 -0500 Subject: [PATCH] improve exception information from MethodCommand --- src/HexManiac.Core/MethodCommand.cs | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/HexManiac.Core/MethodCommand.cs b/src/HexManiac.Core/MethodCommand.cs index c0760d3f..c42e7ddb 100644 --- a/src/HexManiac.Core/MethodCommand.cs +++ b/src/HexManiac.Core/MethodCommand.cs @@ -1,5 +1,6 @@ using System; using System.ComponentModel; +using System.Reflection; using System.Threading.Tasks; using System.Windows.Input; @@ -87,10 +88,15 @@ namespace HavenSoft.HexManiac.Core { var execute = Context.GetType().GetMethod(ExecuteName); if (execute == null) return; object result; - switch (execute.GetParameters().Length) { - case 0: result = execute.Invoke(Context, Array.Empty()); break; - case 1: result = execute.Invoke(Context, new object[] { parameter }); break; - default: throw new InvalidOperationException($"{ExecuteName}: too many parameters!"); + try { + switch (execute.GetParameters().Length) { + case 0: result = execute.Invoke(Context, Array.Empty()); break; + case 1: result = execute.Invoke(Context, new object[] { parameter }); break; + default: throw new InvalidOperationException($"{ExecuteName}: too many parameters!"); + } + } catch (TargetInvocationException e) { + // throw the exception that caused this problem + throw e.InnerException; } if (result is Task task) { task.ContinueWith(t => {