From 7e3d124a240c37e664a641cf39c355431dcc79a2 Mon Sep 17 00:00:00 2001 From: MyDrift Date: Thu, 22 Aug 2024 19:35:02 +0200 Subject: [PATCH] add error handling --- functions/public/Invoke-WPFUIElements.ps1 | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/functions/public/Invoke-WPFUIElements.ps1 b/functions/public/Invoke-WPFUIElements.ps1 index b17623ad..6fcbd19c 100644 --- a/functions/public/Invoke-WPFUIElements.ps1 +++ b/functions/public/Invoke-WPFUIElements.ps1 @@ -36,7 +36,11 @@ function Invoke-WPFUIElements { throw "Failed to retrieve Styles using 'FindResource' from main window element." } - $targetGrid = $window.FindName($targetGridName) + try { + $targetGrid = $window.FindName($targetGridName) + } catch { + throw "Failed to find the target grid '$targetGridName' in the main window." + } # Clear existing ColumnDefinitions and Children $targetGrid.ColumnDefinitions.Clear() | Out-Null