Retain original stack trace when exception happens in Producer (#108)
diff --git a/src/DotPulsar/Internal/Producer.cs b/src/DotPulsar/Internal/Producer.cs
index 91fd6a5..591c52d 100644
--- a/src/DotPulsar/Internal/Producer.cs
+++ b/src/DotPulsar/Internal/Producer.cs
@@ -23,6 +23,7 @@
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Diagnostics;
+using System.Runtime.ExceptionServices;
using System.Threading;
using System.Threading.Tasks;
@@ -226,7 +227,8 @@
{
_ = await _state.StateChangedFrom(ProducerState.Disconnected, cancellationToken).ConfigureAwait(false);
if (_throw is not null)
- throw _throw;
+ //Retain original stack trace by throwing like this
+ ExceptionDispatchInfo.Capture(_throw).Throw();
}
if (_producerCount == 1)