From 519702cd6fd5680054d3203ddf0538cd383db08b Mon Sep 17 00:00:00 2001 From: Vic <10308169+VictoriousRaptor@users.noreply.github.com> Date: Thu, 17 Nov 2022 15:41:25 +0800 Subject: [PATCH] handing exception --- .../Programs/Win32.cs | 27 +++++++++++++------ 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/Plugins/Flow.Launcher.Plugin.Program/Programs/Win32.cs b/Plugins/Flow.Launcher.Plugin.Program/Programs/Win32.cs index 067124b2e..f54135beb 100644 --- a/Plugins/Flow.Launcher.Plugin.Program/Programs/Win32.cs +++ b/Plugins/Flow.Launcher.Plugin.Program/Programs/Win32.cs @@ -224,6 +224,15 @@ namespace Flow.Launcher.Plugin.Program.Programs return Default; } +#if !DEBUG + catch (Exception e) + { + ProgramLogger.LogException($"|Win32|Win32Program|{path}" + + "|An unexpected error occurred in the calling method Win32Program", e); + + return Default; + } +#endif } private static Win32 LnkProgram(string path) @@ -270,16 +279,14 @@ namespace Flow.Launcher.Plugin.Program.Programs "|Error caused likely due to trying to get the description of the program", e); - program.Valid = false; - return program; + return Default; } catch (FileNotFoundException e) { ProgramLogger.LogException($"|Win32|LnkProgram|{path}" + "|An unexpected error occurred in the calling method LnkProgram", e); - program.Valid = false; - return program; + return Default; } #if !DEBUG //Only do a catch all in production. This is so make developer aware of any unhandled exception and add the exception handling in. catch (Exception e) @@ -287,8 +294,7 @@ namespace Flow.Launcher.Plugin.Program.Programs ProgramLogger.LogException($"|Win32|LnkProgram|{path}" + "|An unexpected error occurred in the calling method LnkProgram", e); - program.Valid = false; - return program; + return Default; } #endif } @@ -342,6 +348,13 @@ namespace Flow.Launcher.Plugin.Program.Programs program.Description = info.FileDescription; return program; } + catch (FileNotFoundException e) + { + ProgramLogger.LogException($"|Win32|ExeProgram|{path}" + + $"|File not found when trying to load the program from {path}", e); + + return Default; + } catch (Exception e) when (e is SecurityException || e is UnauthorizedAccessException) { ProgramLogger.LogException($"|Win32|ExeProgram|{path}" + @@ -386,8 +399,6 @@ namespace Flow.Launcher.Plugin.Program.Programs // Remove disabled programs in DisabledProgramSources var programs = ExceptDisabledSource(paths).Select(x => GetProgramFromPath(x, protocols)); - - .Select(x => GetProgramFromPath(x, protocols)); return programs; }