Rethrow loses the stack trace (CA2200)
Esta página aún no está disponible en tu idioma.
Key dotnet.exception.rethrow-loses-stack · Severity warning · Category exception
Microsoft analyzer CA2200. Flags throw ex; inside a catch. It restarts the stack trace at the rethrow, hiding where the failure happened; throw; keeps it.
Incorrect
Section titled “Incorrect”catch (IOException ex){ _logger.LogError(ex, "Upload failed"); throw ex;}Correct
Section titled “Correct”catch (IOException ex){ _logger.LogError(ex, "Upload failed"); throw;}