Skip to content

Commit de0f449

Browse files
stebetmichaelklishin
authored andcommitted
Fixing rethrown exceptions to properly preserve stackframes.
1 parent 0947ed9 commit de0f449

File tree

4 files changed

+12
-10
lines changed

4 files changed

+12
-10
lines changed

projects/RabbitMQ.Client/client/impl/Connection.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -310,11 +310,11 @@ public void Close(ShutdownEventArgs reason, bool abort, TimeSpan timeout)
310310
// Wait for CloseOk in the MainLoop
311311
_session0.Transmit(ConnectionCloseWrapper(reason.ReplyCode, reason.ReplyText));
312312
}
313-
catch (AlreadyClosedException ace)
313+
catch (AlreadyClosedException)
314314
{
315315
if (!abort)
316316
{
317-
throw ace;
317+
throw;
318318
}
319319
}
320320
#pragma warning disable 0168
@@ -330,7 +330,7 @@ public void Close(ShutdownEventArgs reason, bool abort, TimeSpan timeout)
330330
{
331331
if (!abort)
332332
{
333-
throw ioe;
333+
throw;
334334
}
335335
else
336336
{

projects/RabbitMQ.Client/client/impl/Frame.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
using System.Buffers;
4343
using System.IO;
4444
using System.Net.Sockets;
45+
using System.Runtime.ExceptionServices;
4546
using System.Runtime.InteropServices;
4647
using RabbitMQ.Client.Exceptions;
4748
using RabbitMQ.Client.Framing;
@@ -228,7 +229,7 @@ private static void ProcessProtocolHeader(Stream reader)
228229

229230
internal static InboundFrame ReadFrom(Stream reader)
230231
{
231-
int type;
232+
int type = default;
232233

233234
try
234235
{
@@ -247,9 +248,10 @@ internal static InboundFrame ReadFrom(Stream reader)
247248
!(ioe.InnerException is SocketException) ||
248249
((SocketException)ioe.InnerException).SocketErrorCode != SocketError.TimedOut)
249250
{
250-
throw ioe;
251+
throw;
251252
}
252-
throw ioe.InnerException;
253+
254+
ExceptionDispatchInfo.Capture(ioe.InnerException).Throw();
253255
}
254256

255257
if (type == 'A')

projects/RabbitMQ.Client/client/impl/SocketFrameHandler.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -291,10 +291,10 @@ private ITcpClient ConnectUsingAddressFamily(AmqpTcpEndpoint endpoint,
291291
ConnectOrFail(socket, endpoint, timeout);
292292
return socket;
293293
}
294-
catch (ConnectFailureException e)
294+
catch (ConnectFailureException)
295295
{
296296
socket.Dispose();
297-
throw e;
297+
throw;
298298
}
299299
}
300300

projects/Unit/Fixtures.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -499,7 +499,7 @@ private Process ExecRabbitMqCtlUsingDocker(string args, string dockerMachineName
499499
catch (Exception e)
500500
{
501501
ReportExecFailure("rabbitmqctl", args, e.Message);
502-
throw e;
502+
throw;
503503
}
504504
}
505505

@@ -556,7 +556,7 @@ internal Process ExecCommand(string ctl, string args, string changeDirTo)
556556
catch (Exception e)
557557
{
558558
ReportExecFailure(cmd, args, e.Message);
559-
throw e;
559+
throw;
560560
}
561561
}
562562

0 commit comments

Comments
 (0)