// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. using System; namespace CommunityToolkit.HighPerformance.Memory.Internals; /// /// A helper class to throw exceptions for memory types. /// internal static class ThrowHelper { /// /// Throws an when using the * constructor with a managed type. /// public static void ThrowArgumentExceptionForManagedType() { throw new ArgumentException("Can't use a void* constructor when T is a managed type."); } /// /// Throws an when the target span is too short. /// public static void ThrowArgumentExceptionForDestinationTooShort() { throw new ArgumentException("The target span is too short to copy all the current items to."); } /// /// Throws an when the target span does not have the same shape as the source. /// public static void ThrowArgumentExceptionForDestinationWithNotSameShape() { throw new ArgumentException("The target span does not have the same shape as the source one."); } /// /// Throws an when using an array of an invalid type. /// public static void ThrowArrayTypeMismatchException() { throw new ArrayTypeMismatchException("The given array doesn't match the specified type T."); } /// /// Throws an when using an array of an invalid type. /// public static void ThrowArgumentExceptionForUnsupportedType() { throw new ArgumentException("The specified object type is not supported."); } /// /// Throws an when the a given coordinate is invalid. /// /// /// Throwing is technically discouraged in the docs, but /// we're doing that here for consistency with the official type(s) from the BCL. /// public static void ThrowIndexOutOfRangeException() { throw new IndexOutOfRangeException(); } /// /// Throws an when more than one parameter are invalid. /// public static void ThrowArgumentException() { throw new ArgumentException("One or more input parameters were invalid."); } /// /// Throws an when the "depth" parameter is invalid. /// public static void ThrowArgumentOutOfRangeExceptionForDepth() { throw new ArgumentOutOfRangeException("depth"); } /// /// Throws an when the "row" parameter is invalid. /// public static void ThrowArgumentOutOfRangeExceptionForRow() { throw new ArgumentOutOfRangeException("row"); } /// /// Throws an when the "column" parameter is invalid. /// public static void ThrowArgumentOutOfRangeExceptionForColumn() { throw new ArgumentOutOfRangeException("column"); } /// /// Throws an when the "offset" parameter is invalid. /// public static void ThrowArgumentOutOfRangeExceptionForOffset() { throw new ArgumentOutOfRangeException("offset"); } /// /// Throws an when the "height" parameter is invalid. /// public static void ThrowArgumentOutOfRangeExceptionForHeight() { throw new ArgumentOutOfRangeException("height"); } /// /// Throws an when the "width" parameter is invalid. /// public static void ThrowArgumentOutOfRangeExceptionForWidth() { throw new ArgumentOutOfRangeException("width"); } /// /// Throws an when the "pitch" parameter is invalid. /// public static void ThrowArgumentOutOfRangeExceptionForPitch() { throw new ArgumentOutOfRangeException("pitch"); } }