From 92528efaf58e0ed1704fd9e8b4655103801ea410 Mon Sep 17 00:00:00 2001
From: BenjaminS <97973081+benjisho@users.noreply.github.com>
Date: Tue, 30 May 2023 17:05:21 +0300
Subject: [PATCH] Added error handling to Initialize method in Win10Plugin
This pull request adds more robust error handling to the Initialize method in the Win10Plugin class. The changes include:
1. Added a try-catch block to the Initialize method to catch and log any exceptions that occur during initialization.
2. Enhanced the logging of exceptions to include not only the error message but also the entire error content, including the stack trace. This change makes debugging easier by providing more context when an error occurs.
---
src/Greenshot.Plugin.Win10/Win10Plugin.cs | 39 ++++++++++++++---------
1 file changed, 24 insertions(+), 15 deletions(-)
diff --git a/src/Greenshot.Plugin.Win10/Win10Plugin.cs b/src/Greenshot.Plugin.Win10/Win10Plugin.cs
index 6b15ff3c5..ab0447faf 100644
--- a/src/Greenshot.Plugin.Win10/Win10Plugin.cs
+++ b/src/Greenshot.Plugin.Win10/Win10Plugin.cs
@@ -62,23 +62,32 @@ namespace Greenshot.Plugin.Win10
/// true if plugin is initialized, false if not (doesn't show)
public bool Initialize()
{
- // Here we check if the build version of Windows is actually what we support
- if (!WindowsVersion.IsWindows10BuildOrLater(17763))
+ try
{
- Log.WarnFormat("No support for Windows build {0}", WindowsVersion.BuildVersion);
+ // Here we check if the build version of Windows is actually what we support
+ if (!WindowsVersion.IsWindows10BuildOrLater(17763))
+ {
+ Log.WarnFormat("No support for Windows build {0}", WindowsVersion.BuildVersion);
+ return false;
+ }
+
+ SimpleServiceProvider.Current.AddService(ToastNotificationService.Create());
+ // Set this as IOcrProvider
+ SimpleServiceProvider.Current.AddService(new Win10OcrProvider());
+ // Add the processor
+ SimpleServiceProvider.Current.AddService(new Win10OcrProcessor());
+
+ // Add the destinations
+ SimpleServiceProvider.Current.AddService(new Win10OcrDestination());
+ SimpleServiceProvider.Current.AddService(new Win10ShareDestination());
+
+ return true;
+ }
+ catch (Exception e)
+ {
+ Log.Error("Failed to initialize Win10Plugin. Error: " + e.ToString(), e);
return false;
}
-
- SimpleServiceProvider.Current.AddService(ToastNotificationService.Create());
- // Set this as IOcrProvider
- SimpleServiceProvider.Current.AddService(new Win10OcrProvider());
- // Add the processor
- SimpleServiceProvider.Current.AddService(new Win10OcrProcessor());
-
- // Add the destinations
- SimpleServiceProvider.Current.AddService(new Win10OcrDestination());
- SimpleServiceProvider.Current.AddService(new Win10ShareDestination());
- return true;
}
public void Shutdown()
@@ -86,4 +95,4 @@ namespace Greenshot.Plugin.Win10
// Nothing to shutdown
}
}
-}
\ No newline at end of file
+}