From 4f8549f220e9da6eedb24fe37b0543a7189ff8ea Mon Sep 17 00:00:00 2001 From: Huo Yaoyuan Date: Sun, 7 May 2017 00:38:17 +0800 Subject: [PATCH] Standardise usages of exceptions. --- osu.Game.Rulesets.Osu/Replays/OsuAutoGeneratorBase.cs | 4 ++-- osu.Game.Rulesets.Taiko/Replays/TaikoAutoGenerator.cs | 2 +- osu.Game/Database/ScoreDatabase.cs | 4 ++-- osu.Game/Graphics/OsuColour.cs | 2 +- osu.Game/Rulesets/UI/HitRenderer.cs | 2 +- osu.Game/Screens/Play/Player.cs | 4 ++-- 6 files changed, 9 insertions(+), 9 deletions(-) diff --git a/osu.Game.Rulesets.Osu/Replays/OsuAutoGeneratorBase.cs b/osu.Game.Rulesets.Osu/Replays/OsuAutoGeneratorBase.cs index d2cd7a1156..65ed9530f2 100644 --- a/osu.Game.Rulesets.Osu/Replays/OsuAutoGeneratorBase.cs +++ b/osu.Game.Rulesets.Osu/Replays/OsuAutoGeneratorBase.cs @@ -58,8 +58,8 @@ namespace osu.Game.Rulesets.Osu.Replays { public int Compare(ReplayFrame f1, ReplayFrame f2) { - if (f1 == null) throw new NullReferenceException($@"{nameof(f1)} cannot be null"); - if (f2 == null) throw new NullReferenceException($@"{nameof(f2)} cannot be null"); + if (f1 == null) throw new ArgumentNullException(nameof(f1)); + if (f2 == null) throw new ArgumentNullException(nameof(f2)); return f1.Time.CompareTo(f2.Time); } diff --git a/osu.Game.Rulesets.Taiko/Replays/TaikoAutoGenerator.cs b/osu.Game.Rulesets.Taiko/Replays/TaikoAutoGenerator.cs index eec614426f..c3e5597f43 100644 --- a/osu.Game.Rulesets.Taiko/Replays/TaikoAutoGenerator.cs +++ b/osu.Game.Rulesets.Taiko/Replays/TaikoAutoGenerator.cs @@ -109,7 +109,7 @@ namespace osu.Game.Rulesets.Taiko.Replays Frames.Add(new ReplayFrame(h.StartTime, null, null, button)); } else - throw new Exception("Unknown hit object type."); + throw new InvalidOperationException("Unknown hit object type."); Frames.Add(new ReplayFrame(endTime + KEY_UP_DELAY, null, null, ReplayButtonState.None)); diff --git a/osu.Game/Database/ScoreDatabase.cs b/osu.Game/Database/ScoreDatabase.cs index 8ea836aceb..adca76d2ac 100644 --- a/osu.Game/Database/ScoreDatabase.cs +++ b/osu.Game/Database/ScoreDatabase.cs @@ -94,13 +94,13 @@ namespace osu.Game.Database { byte[] properties = new byte[5]; if (replayInStream.Read(properties, 0, 5) != 5) - throw new Exception("input .lzma is too short"); + throw new IOException("input .lzma is too short"); long outSize = 0; for (int i = 0; i < 8; i++) { int v = replayInStream.ReadByte(); if (v < 0) - throw new Exception("Can't Read 1"); + throw new IOException("Can't Read 1"); outSize |= (long)(byte)v << (8 * i); } diff --git a/osu.Game/Graphics/OsuColour.cs b/osu.Game/Graphics/OsuColour.cs index cd719431e7..15ffefc45d 100644 --- a/osu.Game/Graphics/OsuColour.cs +++ b/osu.Game/Graphics/OsuColour.cs @@ -16,7 +16,7 @@ namespace osu.Game.Graphics switch (hex.Length) { default: - throw new Exception(@"Invalid hex string length!"); + throw new ArgumentException(@"Invalid hex string length!"); case 3: return new Color4( (byte)(Convert.ToByte(hex.Substring(0, 1), 16) * 17), diff --git a/osu.Game/Rulesets/UI/HitRenderer.cs b/osu.Game/Rulesets/UI/HitRenderer.cs index 69e0e73664..8ee67df95a 100644 --- a/osu.Game/Rulesets/UI/HitRenderer.cs +++ b/osu.Game/Rulesets/UI/HitRenderer.cs @@ -279,7 +279,7 @@ namespace osu.Game.Rulesets.UI protected abstract Playfield CreatePlayfield(); } - public class BeatmapInvalidForRulesetException : Exception + public class BeatmapInvalidForRulesetException : ArgumentException { public BeatmapInvalidForRulesetException(string text) : base(text) diff --git a/osu.Game/Screens/Play/Player.cs b/osu.Game/Screens/Play/Player.cs index 37b4cf5b45..67bf1e8192 100644 --- a/osu.Game/Screens/Play/Player.cs +++ b/osu.Game/Screens/Play/Player.cs @@ -90,7 +90,7 @@ namespace osu.Game.Screens.Play Beatmap = beatmaps.GetWorkingBeatmap(BeatmapInfo, withStoryboard: true); if (Beatmap?.Beatmap == null) - throw new Exception("Beatmap was not loaded"); + throw new InvalidOperationException("Beatmap was not loaded"); ruleset = osu?.Ruleset.Value ?? Beatmap.BeatmapInfo.Ruleset; rulesetInstance = ruleset.CreateInstance(); @@ -109,7 +109,7 @@ namespace osu.Game.Screens.Play } if (!HitRenderer.Objects.Any()) - throw new Exception("Beatmap contains no hit objects!"); + throw new InvalidOperationException("Beatmap contains no hit objects!"); } catch (Exception e) {