Skip to content

Commit 0df6533

Browse files
authored
Merge pull request #1391 from dotnet/dev/bartde/simpler_exception_rethrow
Ensure all exception rethrows use EDI.
2 parents c8095ee + 4efa318 commit 0df6533

File tree

7 files changed

+11
-25
lines changed

7 files changed

+11
-25
lines changed

Rx.NET/Source/src/System.Reactive/Internal/ExceptionServices.cs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,6 @@ internal static class ExceptionHelpers
1515
[DoesNotReturn]
1616
public static void Throw(this Exception exception) => Services.Value.Rethrow(exception);
1717

18-
public static void ThrowIfNotNull(this Exception? exception)
19-
{
20-
if (exception != null)
21-
{
22-
Services.Value.Rethrow(exception);
23-
}
24-
}
25-
2618
private static IExceptionServices Initialize()
2719
{
2820
#pragma warning disable CS0618 // Type or member is obsolete

Rx.NET/Source/src/System.Reactive/Internal/PushPullAdapter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public bool MoveNext()
6767
done = current.Kind != NotificationKind.OnNext;
6868
}
6969

70-
current.Exception.ThrowIfNotNull();
70+
current.Exception?.Throw();
7171

7272
return current.HasValue;
7373
}

Rx.NET/Source/src/System.Reactive/Linq/Observable/GetEnumerator.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public bool MoveNext()
7070
return true;
7171
}
7272

73-
_error.ThrowIfNotNull();
73+
_error?.Throw();
7474

7575
Debug.Assert(_done);
7676

Rx.NET/Source/src/System.Reactive/Linq/QueryLanguage.Blocking.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ private static TSource FirstOrDefaultInternal<TSource>(IObservable<TSource> sour
7878
consumer.Wait();
7979
}
8080

81-
consumer._error.ThrowIfNotNull();
81+
consumer._error?.Throw();
8282

8383
if (throwOnEmpty && !consumer._hasValue)
8484
{
@@ -101,7 +101,7 @@ public virtual void ForEach<TSource>(IObservable<TSource> source, Action<TSource
101101
sink.Wait();
102102
}
103103

104-
sink.Error.ThrowIfNotNull();
104+
sink.Error?.Throw();
105105
}
106106

107107
public virtual void ForEach<TSource>(IObservable<TSource> source, Action<TSource, int> onNext)
@@ -113,7 +113,7 @@ public virtual void ForEach<TSource>(IObservable<TSource> source, Action<TSource
113113
sink.Wait();
114114
}
115115

116-
sink.Error.ThrowIfNotNull();
116+
sink.Error?.Throw();
117117
}
118118

119119
#endregion
@@ -166,7 +166,7 @@ private static TSource LastOrDefaultInternal<TSource>(IObservable<TSource> sourc
166166
consumer.Wait();
167167
}
168168

169-
consumer._error.ThrowIfNotNull();
169+
consumer._error?.Throw();
170170

171171
if (throwOnEmpty && !consumer._hasValue)
172172
{
@@ -243,7 +243,7 @@ private static TSource SingleOrDefaultInternal<TSource>(IObservable<TSource> sou
243243
consumer.Wait();
244244
}
245245

246-
consumer._error.ThrowIfNotNull();
246+
consumer._error?.Throw();
247247

248248
if (consumer._hasMoreThanOneElement)
249249
{

Rx.NET/Source/src/System.Reactive/Runtime/CompilerServices/TaskObservableMethodBuilder.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@ public T GetResult()
328328
return _subject.GetResult();
329329
}
330330

331-
_exception.ThrowIfNotNull();
331+
_exception?.Throw();
332332

333333
return _result!;
334334
}

Rx.NET/Source/src/System.Reactive/Subjects/AsyncSubject.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -427,7 +427,7 @@ public T GetResult()
427427
e.Wait();
428428
}
429429

430-
_exception.ThrowIfNotNull();
430+
_exception?.Throw();
431431

432432
if (!_hasValue)
433433
{

Rx.NET/Source/src/System.Reactive/Subjects/BehaviorSubject.cs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -84,10 +84,7 @@ public T Value
8484
{
8585
CheckDisposed();
8686

87-
if (_exception != null)
88-
{
89-
throw _exception;
90-
}
87+
_exception?.Throw();
9188

9289
return _value;
9390
}
@@ -121,10 +118,7 @@ public bool TryGetValue([MaybeNullWhen(false)] out T value)
121118
return false;
122119
}
123120

124-
if (_exception != null)
125-
{
126-
throw _exception;
127-
}
121+
_exception?.Throw();
128122

129123
value = _value;
130124
return true;

0 commit comments

Comments
 (0)