mirror of
https://github.com/ppy/osu
synced 2025-01-11 16:49:39 +00:00
Merge pull request #27501 from turbedi/throw_helper
Use ThrowHelper methods in more places
This commit is contained in:
commit
3d8fdc52a4
@ -58,9 +58,9 @@ namespace osu.Game.Rulesets.Osu.Beatmaps
|
|||||||
|
|
||||||
private void applyStacking(Beatmap<OsuHitObject> beatmap, int startIndex, int endIndex)
|
private void applyStacking(Beatmap<OsuHitObject> beatmap, int startIndex, int endIndex)
|
||||||
{
|
{
|
||||||
if (startIndex > endIndex) throw new ArgumentOutOfRangeException(nameof(startIndex), $"{nameof(startIndex)} cannot be greater than {nameof(endIndex)}.");
|
ArgumentOutOfRangeException.ThrowIfGreaterThan(startIndex, endIndex);
|
||||||
if (startIndex < 0) throw new ArgumentOutOfRangeException(nameof(startIndex), $"{nameof(startIndex)} cannot be less than 0.");
|
ArgumentOutOfRangeException.ThrowIfNegative(startIndex);
|
||||||
if (endIndex < 0) throw new ArgumentOutOfRangeException(nameof(endIndex), $"{nameof(endIndex)} cannot be less than 0.");
|
ArgumentOutOfRangeException.ThrowIfNegative(endIndex);
|
||||||
|
|
||||||
int extendedEndIndex = endIndex;
|
int extendedEndIndex = endIndex;
|
||||||
|
|
||||||
|
@ -334,7 +334,7 @@ namespace osu.Game.Rulesets.Osu.Edit
|
|||||||
/// <returns>The <see cref="OsuDistanceSnapGrid"/> from a selected <see cref="HitObject"/> to a target <see cref="HitObject"/>.</returns>
|
/// <returns>The <see cref="OsuDistanceSnapGrid"/> from a selected <see cref="HitObject"/> to a target <see cref="HitObject"/>.</returns>
|
||||||
private OsuDistanceSnapGrid createGrid(Func<HitObject, bool> sourceSelector, int targetOffset = 1)
|
private OsuDistanceSnapGrid createGrid(Func<HitObject, bool> sourceSelector, int targetOffset = 1)
|
||||||
{
|
{
|
||||||
if (targetOffset < 1) throw new ArgumentOutOfRangeException(nameof(targetOffset));
|
ArgumentOutOfRangeException.ThrowIfNegativeOrZero(targetOffset);
|
||||||
|
|
||||||
int sourceIndex = -1;
|
int sourceIndex = -1;
|
||||||
|
|
||||||
|
@ -23,8 +23,7 @@ namespace osu.Game.Beatmaps.Timing
|
|||||||
|
|
||||||
public TimeSignature(int numerator)
|
public TimeSignature(int numerator)
|
||||||
{
|
{
|
||||||
if (numerator < 1)
|
ArgumentOutOfRangeException.ThrowIfNegativeOrZero(numerator);
|
||||||
throw new ArgumentOutOfRangeException(nameof(numerator), numerator, "The numerator of a time signature must be positive.");
|
|
||||||
|
|
||||||
Numerator = numerator;
|
Numerator = numerator;
|
||||||
}
|
}
|
||||||
|
@ -489,8 +489,7 @@ namespace osu.Game.Database
|
|||||||
/// <param name="action">The work to run.</param>
|
/// <param name="action">The work to run.</param>
|
||||||
public Task WriteAsync(Action<Realm> action)
|
public Task WriteAsync(Action<Realm> action)
|
||||||
{
|
{
|
||||||
if (isDisposed)
|
ObjectDisposedException.ThrowIf(isDisposed, this);
|
||||||
throw new ObjectDisposedException(nameof(RealmAccess));
|
|
||||||
|
|
||||||
// Required to ensure the write is tracked and accounted for before disposal.
|
// Required to ensure the write is tracked and accounted for before disposal.
|
||||||
// Can potentially be avoided if we have a need to do so in the future.
|
// Can potentially be avoided if we have a need to do so in the future.
|
||||||
@ -675,8 +674,7 @@ namespace osu.Game.Database
|
|||||||
|
|
||||||
private Realm getRealmInstance()
|
private Realm getRealmInstance()
|
||||||
{
|
{
|
||||||
if (isDisposed)
|
ObjectDisposedException.ThrowIf(isDisposed, this);
|
||||||
throw new ObjectDisposedException(nameof(RealmAccess));
|
|
||||||
|
|
||||||
bool tookSemaphoreLock = false;
|
bool tookSemaphoreLock = false;
|
||||||
|
|
||||||
@ -1189,8 +1187,7 @@ namespace osu.Game.Database
|
|||||||
if (!ThreadSafety.IsUpdateThread)
|
if (!ThreadSafety.IsUpdateThread)
|
||||||
throw new InvalidOperationException(@$"{nameof(BlockAllOperations)} must be called from the update thread.");
|
throw new InvalidOperationException(@$"{nameof(BlockAllOperations)} must be called from the update thread.");
|
||||||
|
|
||||||
if (isDisposed)
|
ObjectDisposedException.ThrowIf(isDisposed, this);
|
||||||
throw new ObjectDisposedException(nameof(RealmAccess));
|
|
||||||
|
|
||||||
SynchronizationContext? syncContext = null;
|
SynchronizationContext? syncContext = null;
|
||||||
|
|
||||||
|
@ -80,8 +80,7 @@ namespace osu.Game.IO
|
|||||||
|
|
||||||
public override Storage GetStorageForDirectory(string path)
|
public override Storage GetStorageForDirectory(string path)
|
||||||
{
|
{
|
||||||
if (string.IsNullOrEmpty(path))
|
ArgumentException.ThrowIfNullOrEmpty(path);
|
||||||
throw new ArgumentException("Must be non-null and not empty string", nameof(path));
|
|
||||||
|
|
||||||
if (!path.EndsWith(Path.DirectorySeparatorChar))
|
if (!path.EndsWith(Path.DirectorySeparatorChar))
|
||||||
path += Path.DirectorySeparatorChar;
|
path += Path.DirectorySeparatorChar;
|
||||||
|
@ -27,8 +27,7 @@ namespace osu.Game.Rulesets.Difficulty.Utils
|
|||||||
|
|
||||||
public ReverseQueue(int initialCapacity)
|
public ReverseQueue(int initialCapacity)
|
||||||
{
|
{
|
||||||
if (initialCapacity <= 0)
|
ArgumentOutOfRangeException.ThrowIfNegativeOrZero(initialCapacity);
|
||||||
throw new ArgumentOutOfRangeException(nameof(initialCapacity));
|
|
||||||
|
|
||||||
items = new T[initialCapacity];
|
items = new T[initialCapacity];
|
||||||
capacity = initialCapacity;
|
capacity = initialCapacity;
|
||||||
|
@ -40,8 +40,7 @@ namespace osu.Game.Rulesets.Objects.Types
|
|||||||
|
|
||||||
public static PathType BSpline(int degree)
|
public static PathType BSpline(int degree)
|
||||||
{
|
{
|
||||||
if (degree <= 0)
|
ArgumentOutOfRangeException.ThrowIfNegativeOrZero(degree);
|
||||||
throw new ArgumentOutOfRangeException(nameof(degree), "The degree of a B-Spline path must be greater than zero.");
|
|
||||||
|
|
||||||
return new PathType { Type = SplineType.BSpline, Degree = degree };
|
return new PathType { Type = SplineType.BSpline, Degree = degree };
|
||||||
}
|
}
|
||||||
|
@ -135,8 +135,7 @@ namespace osu.Game.Rulesets.UI
|
|||||||
protected DrawableRuleset(Ruleset ruleset, IBeatmap beatmap, IReadOnlyList<Mod> mods = null)
|
protected DrawableRuleset(Ruleset ruleset, IBeatmap beatmap, IReadOnlyList<Mod> mods = null)
|
||||||
: base(ruleset)
|
: base(ruleset)
|
||||||
{
|
{
|
||||||
if (beatmap == null)
|
ArgumentNullException.ThrowIfNull(beatmap);
|
||||||
throw new ArgumentNullException(nameof(beatmap), "Beatmap cannot be null.");
|
|
||||||
|
|
||||||
if (!(beatmap is Beatmap<TObject> tBeatmap))
|
if (!(beatmap is Beatmap<TObject> tBeatmap))
|
||||||
throw new ArgumentException($"{GetType()} expected the beatmap to contain hitobjects of type {typeof(TObject)}.", nameof(beatmap));
|
throw new ArgumentException($"{GetType()} expected the beatmap to contain hitobjects of type {typeof(TObject)}.", nameof(beatmap));
|
||||||
|
@ -33,8 +33,7 @@ namespace osu.Game.Screens.Ranking.Statistics
|
|||||||
/// <param name="items">The <see cref="SimpleStatisticItem"/>s to display in this row.</param>
|
/// <param name="items">The <see cref="SimpleStatisticItem"/>s to display in this row.</param>
|
||||||
public SimpleStatisticTable(int columnCount, [ItemNotNull] IEnumerable<SimpleStatisticItem> items)
|
public SimpleStatisticTable(int columnCount, [ItemNotNull] IEnumerable<SimpleStatisticItem> items)
|
||||||
{
|
{
|
||||||
if (columnCount < 1)
|
ArgumentOutOfRangeException.ThrowIfNegativeOrZero(columnCount);
|
||||||
throw new ArgumentOutOfRangeException(nameof(columnCount));
|
|
||||||
|
|
||||||
this.columnCount = columnCount;
|
this.columnCount = columnCount;
|
||||||
this.items = items.ToArray();
|
this.items = items.ToArray();
|
||||||
|
@ -35,8 +35,7 @@ namespace osu.Game.Utils
|
|||||||
/// <param name="capacity">The number of items the queue can hold.</param>
|
/// <param name="capacity">The number of items the queue can hold.</param>
|
||||||
public LimitedCapacityQueue(int capacity)
|
public LimitedCapacityQueue(int capacity)
|
||||||
{
|
{
|
||||||
if (capacity < 0)
|
ArgumentOutOfRangeException.ThrowIfNegative(capacity);
|
||||||
throw new ArgumentOutOfRangeException(nameof(capacity));
|
|
||||||
|
|
||||||
this.capacity = capacity;
|
this.capacity = capacity;
|
||||||
array = new T[capacity];
|
array = new T[capacity];
|
||||||
|
@ -58,7 +58,7 @@ namespace osu.Game.Utils
|
|||||||
/// </param>
|
/// </param>
|
||||||
public static int NextInt(int maxValue, int seed, int series = 0)
|
public static int NextInt(int maxValue, int seed, int series = 0)
|
||||||
{
|
{
|
||||||
if (maxValue <= 0) throw new ArgumentOutOfRangeException(nameof(maxValue));
|
ArgumentOutOfRangeException.ThrowIfNegativeOrZero(maxValue);
|
||||||
|
|
||||||
return (int)(NextULong(seed, series) % (ulong)maxValue);
|
return (int)(NextULong(seed, series) % (ulong)maxValue);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user