Rethrow to preserve stack details
Rethrow to preserve stack details
Microsoft docsDescription
Once an exception is thrown, part of the information it carries is the stack trace. The stack trace is a list of the method call hierarchy that starts with the method that throws the exception and ends with the method that catches the exception. If an exception is rethrown by specifying the exception in the throw statement, the stack trace is restarted at the current method and the list of method calls between the original method that threw the exception and the current method is lost. To keep the original stack trace information with the exception, use the throw statement without specifying the exception.
If you're rethrowing the exception from somewhere other than the handler (catch block), use System.Runtime.ExceptionServices.ExceptionDispatchInfo.Capture(System.Exception) to capture the exception in the handler and System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw when you want to rethrow it.
For more information, see Capture and rethrow exceptions properly.
Cause
An exception is rethrown and the exception is explicitly specified in the throw statement.
How to fix violations
To fix a violation of this rule, rethrow the exception without specifying the exception explicitly.
When to suppress
Do not suppress a warning from this rule.