This is an automated email from the ASF dual-hosted git repository.

blankensteiner pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/pulsar-dotpulsar.git


The following commit(s) were added to refs/heads/master by this push:
     new dc1c25d  Retain original stack trace when exception happens in 
Producer (#108)
dc1c25d is described below

commit dc1c25dd77560c6b718cf1c343f4315a409dded2
Author: jvmdc <[email protected]>
AuthorDate: Fri Aug 5 09:13:23 2022 +0200

    Retain original stack trace when exception happens in Producer (#108)
---
 src/DotPulsar/Internal/Producer.cs | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

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;
 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 @@ public sealed class Producer<TMessage> : 
IProducer<TMessage>, IRegisterEvent
         {
             _ = 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)

Reply via email to