From 845af854bde9d52548063075c52c2bddee75f6aa Mon Sep 17 00:00:00 2001 From: Michael Bucari-Tovo Date: Thu, 26 May 2022 16:29:40 -0600 Subject: [PATCH] Add exception handling to products display --- .../GridView/ProductsDisplay.cs | 27 ++++++++++++------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/Source/LibationWinForms/GridView/ProductsDisplay.cs b/Source/LibationWinForms/GridView/ProductsDisplay.cs index 7e1b2d8a..7c411f3f 100644 --- a/Source/LibationWinForms/GridView/ProductsDisplay.cs +++ b/Source/LibationWinForms/GridView/ProductsDisplay.cs @@ -84,18 +84,25 @@ namespace LibationWinForms.GridView public void Display() { - // don't return early if lib size == 0. this will not update correctly if all books are removed - var lib = DbContexts.GetLibrary_Flat_NoTracking(); - - if (!hasBeenDisplayed) + try { - // bind - productsGrid.BindToGrid(lib); - hasBeenDisplayed = true; - InitialLoaded?.Invoke(this, new()); + // don't return early if lib size == 0. this will not update correctly if all books are removed + var lib = DbContexts.GetLibrary_Flat_NoTracking(); + + if (!hasBeenDisplayed) + { + // bind + productsGrid.BindToGrid(lib); + hasBeenDisplayed = true; + InitialLoaded?.Invoke(this, new()); + } + else + productsGrid.UpdateGrid(lib); + } + catch (Exception ex) + { + Serilog.Log.Error(ex, "Error displaying library in {0}", nameof(ProductsDisplay)); } - else - productsGrid.UpdateGrid(lib); }