From 6b039288d50aa1c4faadae3bee3c53c27cc8e3b2 Mon Sep 17 00:00:00 2001 From: John Gross Date: Fri, 25 Jan 2019 12:31:34 -0800 Subject: [PATCH] Reorder exception logging to reduce duplication --- Torch.Server/Initializer.cs | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/Torch.Server/Initializer.cs b/Torch.Server/Initializer.cs index 3e83980..3a7e11e 100644 --- a/Torch.Server/Initializer.cs +++ b/Torch.Server/Initializer.cs @@ -190,21 +190,29 @@ quit"; } private void LogException(Exception ex) - { + { + if (ex is AggregateException ag) + { + foreach (var e in ag.InnerExceptions) + LogException(e); + + return; + } + + Log.Fatal(ex); + + if (ex is ReflectionTypeLoadException extl) + { + foreach (var exl in extl.LoaderExceptions) + LogException(exl); + + return; + } + if (ex.InnerException != null) { LogException(ex.InnerException); } - - Log.Fatal(ex); - - if (ex is ReflectionTypeLoadException exti) - foreach (Exception exl in exti.LoaderExceptions) - LogException(exl); - - if (ex is AggregateException ag) - foreach (Exception e in ag.InnerExceptions) - LogException(e); } private void HandleException(object sender, UnhandledExceptionEventArgs e)