// 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.Collections.Generic; namespace System.Linq { public static partial class EnumerableEx { /// /// Returns a sequence that throws an exception upon enumeration. /// /// Result sequence element type. /// Exception to throw upon enumerating the resulting sequence. /// Sequence that throws the specified exception upon enumeration. public static IEnumerable Throw(Exception exception) { if (exception == null) throw new ArgumentNullException(nameof(exception)); return ThrowCore(exception); } private static IEnumerable ThrowCore(Exception exception) { throw exception; #pragma warning disable 0162 yield break; #pragma warning restore 0162 } } }