internal static void ThrowIfError(int errorCode, string msg = null) { if (errorCode >= 0) { Log.Info(nameof(AudioIOUtil), "No error."); return; } AudioIOError code = (AudioIOError)errorCode; msg = $"{(msg == null ? "" : msg + " : ")}{ code }"; switch (code) { case AudioIOError.OutOfMemory: throw new OutOfMemoryException(); case AudioIOError.InvalidParameter: throw new ArgumentException(msg); case AudioIOError.DevicePolicyRestriction: case AudioIOError.PermissionDenied: throw new UnauthorizedAccessException(msg); case AudioIOError.SoundPolicy: throw new AudioPolicyException(msg); case AudioIOError.NotSupportedType: case AudioIOError.NotSupported: throw new NotSupportedException(msg); case AudioIOError.DeviceNotOpened: case AudioIOError.DeviceNotClosed: case AudioIOError.InvalidBuffer: case AudioIOError.InvalidOperation: case AudioIOError.InvalidState: default: throw new InvalidOperationException(msg); } }
internal static void ThrowIfFailed(this AudioIOError errorCode, string message) { if (errorCode == AudioIOError.None || !Enum.IsDefined(typeof(AudioIOError), errorCode)) { return; } string errorMessage = $"{ (message ?? "Operation failed") } : { errorCode.ToString() }."; switch (errorCode) { case AudioIOError.OutOfMemory: case AudioIOError.InvalidParameter: throw new ArgumentException(errorMessage); case AudioIOError.DevicePolicyRestriction: case AudioIOError.PermissionDenied: throw new UnauthorizedAccessException(errorMessage); case AudioIOError.SoundPolicy: throw new AudioPolicyException(errorMessage); case AudioIOError.NotSupported: case AudioIOError.NotSupportedType: throw new NotSupportedException(errorMessage); case AudioIOError.DeviceNotOpened: case AudioIOError.DeviceNotClosed: case AudioIOError.InvalidBuffer: case AudioIOError.InvalidOperation: case AudioIOError.InvalidState: throw new InvalidOperationException(errorMessage); default: throw new InvalidOperationException($"{message} : Unknown error({errorCode.ToString()})."); } }