[CSHARP-3990] Use `throw;` instead of `throw ex;` when re-throwing an unwrapped exception in BinaryConnection Created: 08/Dec/21 Updated: 28/Oct/23 Resolved: 04/Jan/22 |
|
| Status: | Closed |
| Project: | C# Driver |
| Component/s: | None |
| Affects Version/s: | 2.14.0 |
| Fix Version/s: | 2.15.0 |
| Type: | Bug | Priority: | Unknown |
| Reporter: | Анатолий Буранов | Assignee: | Robert Stam |
| Resolution: | Fixed | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Backwards Compatibility: | Minor Change |
| Description |
|
Assume a program contains an error in CommandSucceededEvent event handler:
Actual behaviorThe program throws an exception and the exception stack looks like MongoDB driver internal error
(I clipped the rest of the stack) Expected behaviorOn top of the stack trace should have been a frame with my faulty code. Without that, it is hard to find if there is an error in my code. My suggestionI believe the stack trace is cut because of `throw ex` in this code https://github.com/mongodb/mongo-csharp-driver/blob/1123d60823c8c3fc42246282cddfecc8b76479e6/src/MongoDB.Driver.Core/Core/Connections/BinaryConnection.cs#L522 (and some other places) If an exception is not wrapped, then it should be just 'throw', without ex. |
| Comments |
| Comment by Githook User [ 04/Jan/22 ] |
|
Author: {'name': 'rstam', 'email': 'robert@robertstam.org', 'username': 'rstam'}Message: |
| Comment by Robert Stam [ 09/Dec/21 ] |
|
Thank you for reporting this. I agree with your analysis that the issue is caused by calling `throw ex` instead of using `throw` to re-throw. |