from.RollbackTransaction(withdrawalTrxID);
throw new Exception("Withdrawal failed", ex);
Throwing an 'Exception' is not a best practice.
⚠Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.
Who wrote that rule? You? How do you expect that inner exceptions are created in the first place? What if you have an exception handler in the attribute in your controller that logs errors or would you just create exception logging throughout the application and think that's best practice? Good luck with the next programmer not cursing you out when the exception logger is upgraded.
@crtjr64 please read carefully https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/exceptions/creating-and-throwing-exceptions#things-to-avoid-when-throwing-exceptions :)
I read @shatl 's original issue as recommending against throwing System.Exception. Is that what you meant?
@crtjr64 did you think he was recommending against throwing any exception?
@billwagner exactly
I've added this to our backlog, and applied the up-for-grabs label.
The final example should throw a more descriptive exception type, even if the full definition of the exception type is not included in this article.