Skip to content

Commit

Permalink
Catch potential exceptions thrown in YPipe TryRead
Browse files Browse the repository at this point in the history
  • Loading branch information
Thierry Matthey committed Jun 4, 2024
1 parent 47b422d commit 7ecaa5f
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions src/NetMQ/Core/YPipe.cs
Original file line number Diff line number Diff line change
Expand Up @@ -180,17 +180,25 @@ public bool CheckRead()
/// <returns><c>true</c> if the read succeeded, otherwise <c>false</c>.</returns>
public bool TryRead([MaybeNullWhen(returnValue: false)] out T value)
{
// Try to prefetch a value.
if (!CheckRead())
try
{
// Try to prefetch a value.
if (!CheckRead())
{
value = default(T);
return false;
}

// There was at least one value prefetched.
// Return it to the caller.
value = m_queue.Pop();
return true;
}
catch
{
value = default(T);
return false;
}

// There was at least one value prefetched.
// Return it to the caller.
value = m_queue.Pop();
return true;
}

/// <summary>
Expand Down

0 comments on commit 7ecaa5f

Please sign in to comment.