Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Commit a50e974

Browse files
MarcoRossignolitarekgh
authored andcommitted
"Don't directly throw Exception" System.Threading.Tasks.Dataflow (#26052)
* Don't directly throw Exception * Don't directly throw Exception * fix exception message
1 parent 4350f2d commit a50e974

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

src/System.Threading.Tasks.Dataflow/src/Base/DataflowBlock.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1347,13 +1347,12 @@ private void CleanupAndComplete(ReceiveCoreByLinkingCleanupReason reason)
13471347
if (_receivedException == null) _receivedException = CreateExceptionForTimeout();
13481348
goto case ReceiveCoreByLinkingCleanupReason.SourceProtocolError;
13491349
case ReceiveCoreByLinkingCleanupReason.SourceProtocolError:
1350-
case ReceiveCoreByLinkingCleanupReason.ErrorDuringCleanup:
1351-
Debug.Assert(_receivedException != null, "We need an exception with which to fault the task.");
1350+
case ReceiveCoreByLinkingCleanupReason.ErrorDuringCleanup:
13521351
System.Threading.Tasks.Task.Factory.StartNew(state =>
13531352
{
13541353
// Complete with the received exception
13551354
var target = (ReceiveTarget<T>)state;
1356-
try { target.TrySetException(target._receivedException ?? new Exception()); }
1355+
try { target.TrySetException(target._receivedException ?? new InvalidOperationException(SR.InvalidOperation_ErrorDuringCleanup)); }
13571356
catch (ObjectDisposedException) { /* benign race if returned task is already disposed */ }
13581357
}, this, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default);
13591358
break;

src/System.Threading.Tasks.Dataflow/src/Resources/Strings.resx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,4 +97,7 @@
9797
<data name="ConcurrentCollection_SyncRoot_NotSupported" xml:space="preserve">
9898
<value>The SyncRoot property may not be used for the synchronization of concurrent collections.</value>
9999
</data>
100+
<data name="InvalidOperation_ErrorDuringCleanup" xml:space="preserve">
101+
<value>An error occurred while linking up the target or during the cleanup after completion.</value>
102+
</data>
100103
</root>

0 commit comments

Comments
 (0)