Skip to content

Commit 36351f9

Browse files
authored
Fix: Catch COMException when creating submenus to avoid errors (#11363)
1 parent 80643d3 commit 36351f9

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

src/Files.App/Shell/ContextMenu.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public async Task<bool> InvokeVerb(string? verb)
6262

6363
return true;
6464
}
65-
catch (Exception ex) when (ex is COMException || ex is UnauthorizedAccessException)
65+
catch (Exception ex) when (ex is COMException or UnauthorizedAccessException)
6666
{
6767
Debug.WriteLine(ex);
6868
}
@@ -90,7 +90,7 @@ public async Task InvokeItem(int itemID)
9090

9191
Win32API.BringToForeground(currentWindows);
9292
}
93-
catch (Exception ex) when (ex is COMException || ex is UnauthorizedAccessException)
93+
catch (Exception ex) when (ex is COMException or UnauthorizedAccessException)
9494
{
9595
Debug.WriteLine(ex);
9696
}
@@ -110,7 +110,7 @@ public async Task InvokeItem(int itemID)
110110
shellItems.Add(ShellFolderExtensions.GetShellItemFromPathOrPidl(fp));
111111
return GetContextMenuForFiles(shellItems.ToArray(), flags, owningThread, itemFilter);
112112
}
113-
catch (Exception ex) when (ex is ArgumentException || ex is FileNotFoundException)
113+
catch (Exception ex) when (ex is ArgumentException or FileNotFoundException)
114114
{
115115
// Return empty context menu
116116
return null;
@@ -168,7 +168,7 @@ public async Task InvokeItem(int itemID)
168168

169169
return contextMenu;
170170
}
171-
catch (Exception ex) when (ex is ArgumentException || ex is FileNotFoundException)
171+
catch (Exception ex) when (ex is ArgumentException or FileNotFoundException)
172172
{
173173
// Return empty context menu
174174
return null;
@@ -259,7 +259,7 @@ private static void EnumMenuItems(
259259
{
260260
cMenu2?.HandleMenuMsg((uint)User32.WindowMessage.WM_INITMENUPOPUP, (IntPtr)mii.hSubMenu, new IntPtr(ii));
261261
}
262-
catch (NotImplementedException)
262+
catch (Exception ex) when (ex is COMException or NotImplementedException)
263263
{
264264
// Only for dynamic/owner drawn? (open with, etc)
265265
}
@@ -297,15 +297,15 @@ private static void EnumMenuItems(
297297

298298
return commandString.ToString();
299299
}
300-
catch (Exception ex) when (ex is InvalidCastException || ex is ArgumentException)
300+
catch (Exception ex) when (ex is InvalidCastException or ArgumentException)
301301
{
302302
// TODO: Investigate this...
303303
Debug.WriteLine(ex);
304304

305305
return null;
306306
}
307307

308-
catch (Exception ex) when (ex is COMException || ex is NotImplementedException)
308+
catch (Exception ex) when (ex is COMException or NotImplementedException)
309309
{
310310
// Not every item has an associated verb
311311
return null;

0 commit comments

Comments
 (0)