diff --git a/.editorconfig b/.editorconfig index e2bbdd824d..62c37389af 100644 --- a/.editorconfig +++ b/.editorconfig @@ -1136,5 +1136,9 @@ dotnet_diagnostic.RCS1233.severity = warning # Optimize method call. dotnet_diagnostic.RCS1235.severity = warning +# Use exception filter. +dotnet_diagnostic.RCS1236.severity = warning + # Use 'for' statement instead of 'while' statement. dotnet_diagnostic.RCS1239.severity = warning + diff --git a/OpenRA.Game/FileSystem/FileSystem.cs b/OpenRA.Game/FileSystem/FileSystem.cs index c21bbb2170..74fd728216 100644 --- a/OpenRA.Game/FileSystem/FileSystem.cs +++ b/OpenRA.Game/FileSystem/FileSystem.cs @@ -109,10 +109,8 @@ namespace OpenRA.FileSystem Mount(package, explicitName); } - catch + catch when (optional) { - if (!optional) - throw; } } diff --git a/OpenRA.Game/Server/Server.cs b/OpenRA.Game/Server/Server.cs index c1c3b90aa9..1300738e6e 100644 --- a/OpenRA.Game/Server/Server.cs +++ b/OpenRA.Game/Server/Server.cs @@ -248,12 +248,9 @@ namespace OpenRA.Server { listener.Server.SetSocketOption(SocketOptionLevel.IPv6, SocketOptionName.IPv6Only, 1); } - catch (Exception ex) + catch (Exception ex) when (ex is SocketException || ex is ArgumentException) { - if (ex is SocketException || ex is ArgumentException) - Log.Write("server", $"Failed to set socket option on {endpoint}: {ex.Message}"); - else - throw; + Log.Write("server", $"Failed to set socket option on {endpoint}: {ex.Message}"); } listener.Start();