Rule Definition
By explicitly rethrowing the exception, the stack trace is modified so that the rethrowing line appears to be the source. This is almost always certainly a bad idea, as vital information is lost. So be careful how you rethrow exceptions.
Remediation
Use a nested exception in case there is a need to re-throw the exception.
Violation Code Sample
catch (HibernateException ex)
{
if (transaction != null) { transaction.Rollback(); }
throw ex;
}
Fixed Code Sample
catch (HibernateException ex)
{
if (transaction != null) { transaction.Rollback(); }
throw new Exception("Email already in use", ex);
}
______________________________________________
catch (HibernateException ex)
{
if (transaction != null) { transaction.Rollback(); }
throw;
}
Reference
https://www.openmymind.net/FoundationsOfProgramming.pdf p-68
Related Technologies
Technical Criterion
Programming Practices - Error and Exception Handling
About CAST Appmarq
CAST Appmarq is by far the biggest repository of data about real IT systems. It's built on thousands of analyzed applications, made of 35 different technologies, by over 300 business organizations across major verticals. It provides IT Leaders with factual key analytics to let them know if their applications are on track.