From 9f1c872340467e9415229a4ea192979735407293 Mon Sep 17 00:00:00 2001 From: RoosterDragon Date: Sun, 11 Sep 2016 15:14:44 +0100 Subject: [PATCH] Improve some exception types. --- OpenRA.Game/Support/Log.cs | 2 +- OpenRA.Mods.Common/FileFormats/InstallShieldCABCompression.cs | 4 ++-- OpenRA.Mods.Common/Graphics/DefaultSpriteSequence.cs | 2 +- OpenRA.Mods.Common/ServerTraits/LobbyCommands.cs | 2 +- .../Traits/Multipliers/UpgradableMultiplierTrait.cs | 2 +- OpenRA.Mods.D2k/UtilityCommands/D2kMapImporter.cs | 2 +- 6 files changed, 7 insertions(+), 7 deletions(-) diff --git a/OpenRA.Game/Support/Log.cs b/OpenRA.Game/Support/Log.cs index 3c6750eda5..73c0c41def 100644 --- a/OpenRA.Game/Support/Log.cs +++ b/OpenRA.Game/Support/Log.cs @@ -39,7 +39,7 @@ namespace OpenRA ChannelInfo info; lock (Channels) if (!Channels.TryGetValue(channelName, out info)) - throw new Exception("Tried logging to non-existent channel " + channelName); + throw new ArgumentException("Tried logging to non-existent channel " + channelName, "channelName"); return info; } diff --git a/OpenRA.Mods.Common/FileFormats/InstallShieldCABCompression.cs b/OpenRA.Mods.Common/FileFormats/InstallShieldCABCompression.cs index 53b970a483..b741e4db35 100644 --- a/OpenRA.Mods.Common/FileFormats/InstallShieldCABCompression.cs +++ b/OpenRA.Mods.Common/FileFormats/InstallShieldCABCompression.cs @@ -322,7 +322,7 @@ namespace OpenRA.Mods.Common.FileFormats fileOffset = head.FirstFileOffset; } else - throw new Exception("Cannot Resolve Remaining Stream"); + throw new InvalidDataException("Cannot Resolve Remaining Stream"); } else { @@ -403,7 +403,7 @@ namespace OpenRA.Mods.Common.FileFormats void ExtractFile(FileDescriptor file, Stream output, Action onProgress = null) { if (file.Flags.HasFlag(CABFlags.FileInvalid)) - throw new Exception("File Invalid"); + throw new InvalidDataException("File Invalid"); if (file.LinkFlags.HasFlag(LinkFlags.Prev)) { diff --git a/OpenRA.Mods.Common/Graphics/DefaultSpriteSequence.cs b/OpenRA.Mods.Common/Graphics/DefaultSpriteSequence.cs index 77d546e133..3198ff646b 100644 --- a/OpenRA.Mods.Common/Graphics/DefaultSpriteSequence.cs +++ b/OpenRA.Mods.Common/Graphics/DefaultSpriteSequence.cs @@ -48,7 +48,7 @@ namespace OpenRA.Mods.Common.Graphics } catch (Exception e) { - throw new Exception("Error occurred while parsing {0}".F(node.Key), e); + throw new InvalidDataException("Error occurred while parsing {0}".F(node.Key), e); } foreach (var kvp in nodes) diff --git a/OpenRA.Mods.Common/ServerTraits/LobbyCommands.cs b/OpenRA.Mods.Common/ServerTraits/LobbyCommands.cs index 79c939139d..becc7723b2 100644 --- a/OpenRA.Mods.Common/ServerTraits/LobbyCommands.cs +++ b/OpenRA.Mods.Common/ServerTraits/LobbyCommands.cs @@ -756,7 +756,7 @@ namespace OpenRA.Mods.Common.Server var uid = server.LobbyInfo.GlobalSettings.Map; server.Map = server.ModData.MapCache[uid]; if (server.Map.Status != MapStatus.Available) - throw new Exception("Map {0} not found".F(uid)); + throw new InvalidOperationException("Map {0} not found".F(uid)); server.LobbyInfo.Slots = server.Map.Players.Players .Select(p => MakeSlotFromPlayerReference(p.Value)) diff --git a/OpenRA.Mods.Common/Traits/Multipliers/UpgradableMultiplierTrait.cs b/OpenRA.Mods.Common/Traits/Multipliers/UpgradableMultiplierTrait.cs index 060d8a294b..8afddb927e 100644 --- a/OpenRA.Mods.Common/Traits/Multipliers/UpgradableMultiplierTrait.cs +++ b/OpenRA.Mods.Common/Traits/Multipliers/UpgradableMultiplierTrait.cs @@ -45,7 +45,7 @@ namespace OpenRA.Mods.Common.Traits protected UpgradeMultiplierTrait(UpgradeMultiplierTraitInfo info, string modifierType, string actorType) { if (info.Modifier.Length == 0) - throw new Exception("No modifiers in " + modifierType + " for " + actorType); + throw new ArgumentException("No modifiers in " + modifierType + " for " + actorType); this.info = info; IsTraitDisabled = info.UpgradeTypes.Length > 0 && info.BaseLevel > 0; level = IsTraitDisabled ? 0 : info.BaseLevel; diff --git a/OpenRA.Mods.D2k/UtilityCommands/D2kMapImporter.cs b/OpenRA.Mods.D2k/UtilityCommands/D2kMapImporter.cs index 619e9c4661..ff4c52ab40 100644 --- a/OpenRA.Mods.D2k/UtilityCommands/D2kMapImporter.cs +++ b/OpenRA.Mods.D2k/UtilityCommands/D2kMapImporter.cs @@ -276,7 +276,7 @@ namespace OpenRA.Mods.D2k.UtilityCommands stream = File.OpenRead(filename); if (stream.Length == 0 || stream.Length % 4 != 0) - throw new Exception("The map is in an unrecognized format!"); + throw new ArgumentException("The map is in an unrecognized format!", "filename"); Initialize(filename); FillMap();