// 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;
using System.ComponentModel;
using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Runtime.InteropServices;
using System.Threading;
namespace CommunityToolkit.Diagnostics;
///
/// Helper methods to efficiently throw exceptions.
///
public static partial class ThrowHelper
{
///
/// Throws a new .
///
/// Thrown with no parameters.
[DoesNotReturn]
public static void ThrowArrayTypeMismatchException()
{
throw new ArrayTypeMismatchException();
}
///
/// Throws a new .
///
/// The message to include in the exception.
/// Thrown with the specified parameter.
[DoesNotReturn]
public static void ThrowArrayTypeMismatchException(string? message)
{
throw new ArrayTypeMismatchException(message);
}
///
/// Throws a new .
///
/// The message to include in the exception.
/// The inner to include.
/// Thrown with the specified parameters.
[DoesNotReturn]
public static void ThrowArrayTypeMismatchException(string? message, Exception? innerException)
{
throw new ArrayTypeMismatchException(message, innerException);
}
///
/// Throws a new .
///
/// Thrown with no parameters.
[DoesNotReturn]
public static void ThrowArgumentException()
{
throw new ArgumentException();
}
///
/// Throws a new .
///
/// The message to include in the exception.
/// Thrown with the specified parameter.
[DoesNotReturn]
public static void ThrowArgumentException(string? message)
{
throw new ArgumentException(message);
}
///
/// Throws a new .
///
/// The message to include in the exception.
/// The inner to include.
/// Thrown with the specified parameters.
[DoesNotReturn]
public static void ThrowArgumentException(string? message, Exception? innerException)
{
throw new ArgumentException(message, innerException);
}
///
/// Throws a new .
///
/// The argument name.
/// The message to include in the exception.
/// Thrown with the specified parameters.
[DoesNotReturn]
public static void ThrowArgumentException(string? name, string? message)
{
throw new ArgumentException(message, name);
}
///
/// Throws a new .
///
/// The argument name.
/// The message to include in the exception.
/// The inner to include.
/// Thrown with the specified parameters.
[DoesNotReturn]
public static void ThrowArgumentException(string? name, string? message, Exception? innerException)
{
throw new ArgumentException(message, name, innerException);
}
///
/// Throws a new .
///
/// Thrown with no parameters.
[DoesNotReturn]
public static void ThrowArgumentNullException()
{
throw new ArgumentNullException();
}
///
/// Throws a new .
///
/// The argument name.
/// Thrown with the specified parameter.
[DoesNotReturn]
public static void ThrowArgumentNullException(string? name)
{
throw new ArgumentNullException(name);
}
///
/// Throws a new .
///
/// The argument name.
/// The inner to include.
/// Thrown with the specified parameters.
[DoesNotReturn]
public static void ThrowArgumentNullException(string? name, Exception? innerException)
{
throw new ArgumentNullException(name, innerException);
}
///
/// Throws a new .
///
/// The argument name.
/// The message to include in the exception.
/// Thrown with the specified parameters.
[DoesNotReturn]
public static void ThrowArgumentNullException(string? name, string? message)
{
throw new ArgumentNullException(name, message);
}
///
/// Throws a new .
///
/// Thrown with no parameters.
[DoesNotReturn]
public static void ThrowArgumentOutOfRangeException()
{
throw new ArgumentOutOfRangeException();
}
///
/// Throws a new .
///
/// The argument name.
/// Thrown with the specified parameter.
[DoesNotReturn]
public static void ThrowArgumentOutOfRangeException(string? name)
{
throw new ArgumentOutOfRangeException(name);
}
///
/// Throws a new .
///
/// The argument name.
/// The inner to include.
/// Thrown with the specified parameter.
[DoesNotReturn]
public static void ThrowArgumentOutOfRangeException(string? name, Exception? innerException)
{
throw new ArgumentOutOfRangeException(name, innerException);
}
///
/// Throws a new .
///
/// The argument name.
/// The message to include in the exception.
/// Thrown with the specified parameters.
[DoesNotReturn]
public static void ThrowArgumentOutOfRangeException(string? name, string? message)
{
throw new ArgumentOutOfRangeException(name, message);
}
///
/// Throws a new .
///
/// The argument name.
/// The current argument value.
/// The message to include in the exception.
/// Thrown with the specified parameters.
[DoesNotReturn]
public static void ThrowArgumentOutOfRangeException(string? name, object? value, string? message)
{
throw new ArgumentOutOfRangeException(name, value, message);
}
///
/// Throws a new .
///
/// Thrown with no parameters.
[DoesNotReturn]
public static void ThrowCOMException()
{
throw new COMException();
}
///
/// Throws a new .
///
/// The message to include in the exception.
/// Thrown with the specified parameter.
[DoesNotReturn]
public static void ThrowCOMException(string? message)
{
throw new COMException(message);
}
///
/// Throws a new .
///
/// The argument name.
/// The inner to include.
/// Thrown with the specified parameters.
[DoesNotReturn]
public static void ThrowCOMException(string? message, Exception? innerException)
{
throw new COMException(message, innerException);
}
///
/// Throws a new .
///
/// The argument name.
/// The HRESULT of the error to include.
/// Thrown with the specified parameters.
[DoesNotReturn]
public static void ThrowCOMException(string? message, int error)
{
throw new COMException(message, error);
}
///
/// Throws a new .
///
/// Thrown with no parameters.
[DoesNotReturn]
public static void ThrowExternalException()
{
throw new ExternalException();
}
///
/// Throws a new .
///
/// The message to include in the exception.
/// Thrown with the specified parameter.
[DoesNotReturn]
public static void ThrowExternalException(string? message)
{
throw new ExternalException(message);
}
///
/// Throws a new .
///
/// The argument name.
/// The inner to include.
/// Thrown with the specified parameters.
[DoesNotReturn]
public static void ThrowExternalException(string? message, Exception? innerException)
{
throw new ExternalException(message, innerException);
}
///
/// Throws a new .
///
/// The argument name.
/// The HRESULT of the error to include.
/// Thrown with the specified parameters.
[DoesNotReturn]
public static void ThrowExternalException(string? message, int error)
{
throw new ExternalException(message, error);
}
///
/// Throws a new .
///
/// Thrown with no parameters.
[DoesNotReturn]
public static void ThrowFormatException()
{
throw new FormatException();
}
///
/// Throws a new .
///
/// The message to include in the exception.
/// Thrown with the specified parameter.
[DoesNotReturn]
public static void ThrowFormatException(string? message)
{
throw new FormatException(message);
}
///
/// Throws a new .
///
/// The message to include in the exception.
/// The inner to include.
/// Thrown with the specified parameter.
[DoesNotReturn]
public static void ThrowFormatException(string? message, Exception? innerException)
{
throw new FormatException(message, innerException);
}
///
/// Throws a new .
///
/// Thrown with no parameters.
[DoesNotReturn]
public static void ThrowInsufficientMemoryException()
{
throw new InsufficientMemoryException();
}
///
/// Throws a new .
///
/// The message to include in the exception.
/// Thrown with the specified parameter.
[DoesNotReturn]
public static void ThrowInsufficientMemoryException(string? message)
{
throw new InsufficientMemoryException(message);
}
///
/// Throws a new .
///
/// The message to include in the exception.
/// The inner to include.
/// Thrown with the specified parameter.
[DoesNotReturn]
public static void ThrowInsufficientMemoryException(string? message, Exception? innerException)
{
throw new InsufficientMemoryException(message, innerException);
}
///
/// Throws a new .
///
/// Thrown with no parameters.
[DoesNotReturn]
public static void ThrowInvalidDataException()
{
throw new InvalidDataException();
}
///
/// Throws a new .
///
/// The message to include in the exception.
/// Thrown with the specified parameter.
[DoesNotReturn]
public static void ThrowInvalidDataException(string? message)
{
throw new InvalidDataException(message);
}
///
/// Throws a new .
///
/// The message to include in the exception.
/// The inner to include.
/// Thrown with the specified parameter.
[DoesNotReturn]
public static void ThrowInvalidDataException(string? message, Exception? innerException)
{
throw new InvalidDataException(message, innerException);
}
///
/// Throws a new .
///
/// Thrown with no parameters.
[DoesNotReturn]
public static void ThrowInvalidOperationException()
{
throw new InvalidOperationException();
}
///
/// Throws a new .
///
/// The message to include in the exception.
/// Thrown with the specified parameter.
[DoesNotReturn]
public static void ThrowInvalidOperationException(string? message)
{
throw new InvalidOperationException(message);
}
///
/// Throws a new .
///
/// The message to include in the exception.
/// The inner to include.
/// Thrown with the specified parameter.
[DoesNotReturn]
public static void ThrowInvalidOperationException(string? message, Exception? innerException)
{
throw new InvalidOperationException(message, innerException);
}
///
/// Throws a new .
///
/// Thrown with no parameters.
[DoesNotReturn]
public static void ThrowLockRecursionException()
{
throw new LockRecursionException();
}
///
/// Throws a new .
///
/// The message to include in the exception.
/// Thrown with the specified parameter.
[DoesNotReturn]
public static void ThrowLockRecursionException(string? message)
{
throw new LockRecursionException(message);
}
///
/// Throws a new .
///
/// The message to include in the exception.
/// The inner to include.
/// Thrown with the specified parameter.
[DoesNotReturn]
public static void ThrowLockRecursionException(string? message, Exception? innerException)
{
throw new LockRecursionException(message, innerException);
}
///
/// Throws a new .
///
/// Thrown with no parameters.
[DoesNotReturn]
public static void ThrowMissingFieldException()
{
throw new MissingFieldException();
}
///
/// Throws a new .
///
/// The message to include in the exception.
/// Thrown with the specified parameter.
[DoesNotReturn]
public static void ThrowMissingFieldException(string? message)
{
throw new MissingFieldException(message);
}
///
/// Throws a new .
///
/// The message to include in the exception.
/// The inner to include.
/// Thrown with the specified parameter.
[DoesNotReturn]
public static void ThrowMissingFieldException(string? message, Exception? innerException)
{
throw new MissingFieldException(message, innerException);
}
///
/// Throws a new .
///
/// The target class being inspected.
/// The target field being retrieved.
/// Thrown with the specified parameters.
[DoesNotReturn]
public static void ThrowMissingFieldException(string? className, string? fieldName)
{
throw new MissingFieldException(className, fieldName);
}
///
/// Throws a new .
///
/// Thrown with no parameters.
[DoesNotReturn]
public static void ThrowMissingMemberException()
{
throw new MissingMemberException();
}
///
/// Throws a new .
///
/// The message to include in the exception.
/// Thrown with the specified parameter.
[DoesNotReturn]
public static void ThrowMissingMemberException(string? message)
{
throw new MissingMemberException(message);
}
///
/// Throws a new .
///
/// The message to include in the exception.
/// The inner to include.
/// Thrown with the specified parameter.
[DoesNotReturn]
public static void ThrowMissingMemberException(string? message, Exception? innerException)
{
throw new MissingMemberException(message, innerException);
}
///
/// Throws a new .
///
/// The target class being inspected.
/// The target member being retrieved.
/// Thrown with the specified parameters.
[DoesNotReturn]
public static void ThrowMissingMemberException(string? className, string? memberName)
{
throw new MissingMemberException(className, memberName);
}
///
/// Throws a new .
///
/// Thrown with no parameters.
[DoesNotReturn]
public static void ThrowMissingMethodException()
{
throw new MissingMethodException();
}
///
/// Throws a new .
///
/// The message to include in the exception.
/// Thrown with the specified parameter.
[DoesNotReturn]
public static void ThrowMissingMethodException(string? message)
{
throw new MissingMethodException(message);
}
///
/// Throws a new .
///
/// The message to include in the exception.
/// The inner to include.
/// Thrown with the specified parameter.
[DoesNotReturn]
public static void ThrowMissingMethodException(string? message, Exception? innerException)
{
throw new MissingMethodException(message, innerException);
}
///
/// Throws a new .
///
/// The target class being inspected.
/// The target method being retrieved.
/// Thrown with the specified parameters.
[DoesNotReturn]
public static void ThrowMissingMethodException(string? className, string? methodName)
{
throw new MissingMethodException(className, methodName);
}
///
/// Throws a new .
///
/// Thrown with no parameters.
[DoesNotReturn]
public static void ThrowNotSupportedException()
{
throw new NotSupportedException();
}
///
/// Throws a new .
///
/// The message to include in the exception.
/// Thrown with the specified parameter.
[DoesNotReturn]
public static void ThrowNotSupportedException(string? message)
{
throw new NotSupportedException(message);
}
///
/// Throws a new .
///
/// The message to include in the exception.
/// The inner to include.
/// Thrown with the specified parameter.
[DoesNotReturn]
public static void ThrowNotSupportedException(string? message, Exception? innerException)
{
throw new NotSupportedException(message, innerException);
}
///
/// Throws a new .
///
/// The name of the disposed object.
/// Thrown with the specified parameter.
[DoesNotReturn]
public static void ThrowObjectDisposedException(string? objectName)
{
throw new ObjectDisposedException(objectName);
}
///
/// Throws a new .
///
/// The name of the disposed object.
/// The inner to include.
/// Thrown with the specified parameter.
[DoesNotReturn]
public static void ThrowObjectDisposedException(string? objectName, Exception? innerException)
{
throw new ObjectDisposedException(objectName, innerException);
}
///
/// Throws a new .
///
/// The name of the disposed object.
/// The message to include in the exception.
/// Thrown with the specified parameters.
[DoesNotReturn]
public static void ThrowObjectDisposedException(string? objectName, string? message)
{
throw new ObjectDisposedException(objectName, message);
}
///
/// Throws a new .
///
/// Thrown with no parameters.
[DoesNotReturn]
public static void ThrowOperationCanceledException()
{
throw new OperationCanceledException();
}
///
/// Throws a new .
///
/// The message to include in the exception.
/// Thrown with the specified parameter.
[DoesNotReturn]
public static void ThrowOperationCanceledException(string? message)
{
throw new OperationCanceledException(message);
}
///
/// Throws a new .
///
/// The message to include in the exception.
/// The inner to include.
/// Thrown with the specified parameter.
[DoesNotReturn]
public static void ThrowOperationCanceledException(string? message, Exception? innerException)
{
throw new OperationCanceledException(message, innerException);
}
///
/// Throws a new .
///
/// The in use.
/// Thrown with the specified parameters.
[DoesNotReturn]
public static void ThrowOperationCanceledException(CancellationToken token)
{
throw new OperationCanceledException(token);
}
///
/// Throws a new .
///
/// The message to include in the exception.
/// The in use.
/// Thrown with the specified parameters.
[DoesNotReturn]
public static void ThrowOperationCanceledException(string? message, CancellationToken token)
{
throw new OperationCanceledException(message, token);
}
///
/// Throws a new .
///
/// The message to include in the exception.
/// The inner to include.
/// The in use.
/// Thrown with the specified parameters.
[DoesNotReturn]
public static void ThrowOperationCanceledException(string? message, Exception? innerException, CancellationToken token)
{
throw new OperationCanceledException(message, innerException, token);
}
///
/// Throws a new .
///
/// Thrown with no parameters.
[DoesNotReturn]
public static void ThrowPlatformNotSupportedException()
{
throw new PlatformNotSupportedException();
}
///
/// Throws a new .
///
/// The message to include in the exception.
/// Thrown with the specified parameter.
[DoesNotReturn]
public static void ThrowPlatformNotSupportedException(string? message)
{
throw new PlatformNotSupportedException(message);
}
///
/// Throws a new .
///
/// The message to include in the exception.
/// The inner to include.
/// Thrown with the specified parameter.
[DoesNotReturn]
public static void ThrowPlatformNotSupportedException(string? message, Exception? innerException)
{
throw new PlatformNotSupportedException(message, innerException);
}
///
/// Throws a new .
///
/// Thrown with no parameters.
[DoesNotReturn]
public static void ThrowSynchronizationLockException()
{
throw new SynchronizationLockException();
}
///
/// Throws a new .
///
/// The message to include in the exception.
/// Thrown with the specified parameter.
[DoesNotReturn]
public static void ThrowSynchronizationLockException(string? message)
{
throw new SynchronizationLockException(message);
}
///
/// Throws a new .
///
/// The message to include in the exception.
/// The inner to include.
/// Thrown with the specified parameter.
[DoesNotReturn]
public static void ThrowSynchronizationLockException(string? message, Exception? innerException)
{
throw new SynchronizationLockException(message, innerException);
}
///
/// Throws a new .
///
/// Thrown with no parameters.
[DoesNotReturn]
public static void ThrowTimeoutException()
{
throw new TimeoutException();
}
///
/// Throws a new .
///
/// The message to include in the exception.
/// Thrown with the specified parameter.
[DoesNotReturn]
public static void ThrowTimeoutException(string? message)
{
throw new TimeoutException(message);
}
///
/// Throws a new .
///
/// The message to include in the exception.
/// The inner to include.
/// Thrown with the specified parameter.
[DoesNotReturn]
public static void ThrowTimeoutException(string? message, Exception? innerException)
{
throw new TimeoutException(message, innerException);
}
///
/// Throws a new .
///
/// Thrown with no parameters.
[DoesNotReturn]
public static void ThrowUnauthorizedAccessException()
{
throw new UnauthorizedAccessException();
}
///
/// Throws a new .
///
/// The message to include in the exception.
/// Thrown with the specified parameter.
[DoesNotReturn]
public static void ThrowUnauthorizedAccessException(string? message)
{
throw new UnauthorizedAccessException(message);
}
///
/// Throws a new .
///
/// The message to include in the exception.
/// The inner to include.
/// Thrown with the specified parameter.
[DoesNotReturn]
public static void ThrowUnauthorizedAccessException(string? message, Exception? innerException)
{
throw new UnauthorizedAccessException(message, innerException);
}
///
/// Throws a new .
///
/// Thrown with no parameters.
[DoesNotReturn]
public static void ThrowWin32Exception()
{
throw new Win32Exception();
}
///
/// Throws a new .
///
/// The Win32 error code associated with this exception.
/// Thrown with the specified parameter.
[DoesNotReturn]
public static void ThrowWin32Exception(int error)
{
throw new Win32Exception(error);
}
///
/// Throws a new .
///
/// The Win32 error code associated with this exception.
/// The message to include in the exception.
/// Thrown with the specified parameter.
[DoesNotReturn]
public static void ThrowWin32Exception(int error, string? message)
{
throw new Win32Exception(error, message);
}
///
/// Throws a new .
///
/// The message to include in the exception.
/// Thrown with the specified parameter.
[DoesNotReturn]
public static void ThrowWin32Exception(string? message)
{
throw new Win32Exception(message);
}
///
/// Throws a new .
///
/// The message to include in the exception.
/// The inner to include.
/// Thrown with the specified parameter.
[DoesNotReturn]
public static void ThrowWin32Exception(string? message, Exception? innerException)
{
throw new Win32Exception(message, innerException);
}
}