Skip to content

Fix: Catch COMException when creating submenus to avoid errors #11363

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 19, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions src/Files.App/Shell/ContextMenu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public async Task<bool> InvokeVerb(string? verb)

return true;
}
catch (Exception ex) when (ex is COMException || ex is UnauthorizedAccessException)
catch (Exception ex) when (ex is COMException or UnauthorizedAccessException)
{
Debug.WriteLine(ex);
}
Expand Down Expand Up @@ -90,7 +90,7 @@ public async Task InvokeItem(int itemID)

Win32API.BringToForeground(currentWindows);
}
catch (Exception ex) when (ex is COMException || ex is UnauthorizedAccessException)
catch (Exception ex) when (ex is COMException or UnauthorizedAccessException)
{
Debug.WriteLine(ex);
}
Expand All @@ -110,7 +110,7 @@ public async Task InvokeItem(int itemID)
shellItems.Add(ShellFolderExtensions.GetShellItemFromPathOrPidl(fp));
return GetContextMenuForFiles(shellItems.ToArray(), flags, owningThread, itemFilter);
}
catch (Exception ex) when (ex is ArgumentException || ex is FileNotFoundException)
catch (Exception ex) when (ex is ArgumentException or FileNotFoundException)
{
// Return empty context menu
return null;
Expand Down Expand Up @@ -168,7 +168,7 @@ public async Task InvokeItem(int itemID)

return contextMenu;
}
catch (Exception ex) when (ex is ArgumentException || ex is FileNotFoundException)
catch (Exception ex) when (ex is ArgumentException or FileNotFoundException)
{
// Return empty context menu
return null;
Expand Down Expand Up @@ -259,7 +259,7 @@ private static void EnumMenuItems(
{
cMenu2?.HandleMenuMsg((uint)User32.WindowMessage.WM_INITMENUPOPUP, (IntPtr)mii.hSubMenu, new IntPtr(ii));
}
catch (NotImplementedException)
catch (Exception ex) when (ex is COMException or NotImplementedException)
{
// Only for dynamic/owner drawn? (open with, etc)
}
Expand Down Expand Up @@ -297,15 +297,15 @@ private static void EnumMenuItems(

return commandString.ToString();
}
catch (Exception ex) when (ex is InvalidCastException || ex is ArgumentException)
catch (Exception ex) when (ex is InvalidCastException or ArgumentException)
{
// TODO: Investigate this...
Debug.WriteLine(ex);

return null;
}

catch (Exception ex) when (ex is COMException || ex is NotImplementedException)
catch (Exception ex) when (ex is COMException or NotImplementedException)
{
// Not every item has an associated verb
return null;
Expand Down