diff --git a/src/NetMQ/Core/YPipe.cs b/src/NetMQ/Core/YPipe.cs
index 61f002df..61fc807c 100644
--- a/src/NetMQ/Core/YPipe.cs
+++ b/src/NetMQ/Core/YPipe.cs
@@ -180,17 +180,25 @@ public bool CheckRead()
/// true if the read succeeded, otherwise false.
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;
}
///