Method OnErrorResumeNext
| Edit this page View SourceOnErrorResumeNext<TSource>(IEnumerable<TSource>, IEnumerable<TSource>)
Creates a sequence that concatenates both given sequences, regardless of whether an error occurs.
Declaration
public static IEnumerable<TSource> OnErrorResumeNext<TSource>(this IEnumerable<TSource> first, IEnumerable<TSource> second)
Parameters
Type | Name | Description |
---|---|---|
IEnumerable<TSource> | first | First sequence. |
IEnumerable<TSource> | second | Second sequence. |
Returns
Type | Description |
---|---|
IEnumerable<TSource> | Sequence concatenating the elements of both sequences, ignoring errors. |
Type Parameters
Name | Description |
---|---|
TSource | Source sequence element type. |
Remarks
first
is enumerated until either the sequence completes or an error occurs during
enumeration. After either of these events, second
is then enumerated in the same way.
This operator uses deferred execution and streams its results.
Examples
The following code example demonstrates how to concatenate multiple sequences, regardless of any errors that may occur, using OnErrorResumeNext
.
// this sequence will throw an exception on the 6th element
var sequence = Enumerable.Range(1, 5)
.Concat(SuperEnumerable.Throw<int>(new InvalidOperationException()));
// Skip over the error and enumerate the second sequence
var result = sequence
.OnErrorResumeNext(
Enumerable.Range(1, 5));
Console.WriteLine(
"[" +
string.Join(", ", result) +
"]");
// This code produces the following output:
// [1, 2, 3, 4, 5, 1, 2, 3, 4, 5]
Exceptions
Type | Condition |
---|---|
ArgumentNullException |
|
OnErrorResumeNext<TSource>(params IEnumerable<TSource>[])
Creates a sequence that concatenates the given sequences, regardless of whether an error occurs in any of the sequences.
Declaration
public static IEnumerable<TSource> OnErrorResumeNext<TSource>(params IEnumerable<TSource>[] sources)
Parameters
Type | Name | Description |
---|---|---|
IEnumerable<TSource>[] | sources | Source sequences. |
Returns
Type | Description |
---|---|
IEnumerable<TSource> | Sequence concatenating the elements of the given sequences, ignoring errors. |
Type Parameters
Name | Description |
---|---|
TSource | Source sequence element type. |
Remarks
Each sequence of sources
is enumerated until either the sequence completes or an error occurs during
enumeration. The returned sequence completes when all sub-sequences have been enumerated in this manner.
This operator uses deferred execution and streams its results.
Examples
The following code example demonstrates how to concatenate multiple sequences, regardless of any errors that may occur, using OnErrorResumeNext
.
// this sequence will throw an exception on the 6th element
var sequence = Enumerable.Range(1, 5)
.Concat(SuperEnumerable.Throw<int>(new InvalidOperationException()));
// Skip over the error and enumerate the second sequence
var result = SuperEnumerable
.OnErrorResumeNext(
sequence,
Enumerable.Range(1, 5));
Console.WriteLine(
"[" +
string.Join(", ", result) +
"]");
// This code produces the following output:
// [1, 2, 3, 4, 5, 1, 2, 3, 4, 5]
Exceptions
Type | Condition |
---|---|
ArgumentNullException |
|
OnErrorResumeNext<TSource>(IEnumerable<IEnumerable<TSource>>)
Creates a sequence that concatenates the given sequences, regardless of whether an error occurs in any of the sequences.
Declaration
public static IEnumerable<TSource> OnErrorResumeNext<TSource>(this IEnumerable<IEnumerable<TSource>> sources)
Parameters
Type | Name | Description |
---|---|---|
IEnumerable<IEnumerable<TSource>> | sources | Source sequences. |
Returns
Type | Description |
---|---|
IEnumerable<TSource> | Sequence concatenating the elements of the given sequences, ignoring errors. |
Type Parameters
Name | Description |
---|---|
TSource | Source sequence element type. |
Remarks
Each sequence of sources
is enumerated until either the sequence completes or an error occurs during
enumeration. The returned sequence completes when all sub-sequences have been enumerated in this manner.
This operator uses deferred execution and streams its results.
Examples
The following code example demonstrates how to concatenate multiple sequences, regardless of any errors that may occur, using OnErrorResumeNext
.
// this sequence will throw an exception on the 6th element
var sequence = Enumerable.Range(1, 5)
.Concat(SuperEnumerable.Throw<int>(new InvalidOperationException()));
// Skip over the error and enumerate the second sequence
var result = new[] { sequence, Enumerable.Range(1, 5), }
.OnErrorResumeNext();
Console.WriteLine(
"[" +
string.Join(", ", result) +
"]");
// This code produces the following output:
// [1, 2, 3, 4, 5, 1, 2, 3, 4, 5]
Exceptions
Type | Condition |
---|---|
ArgumentNullException |
|