
Inline adoc files when they are included exactly once. Also fix language tags because this inlining gives us better information on what language the code is written in.
72 lines
1.5 KiB
Plaintext
72 lines
1.5 KiB
Plaintext
== Why is this an issue?
|
|
|
|
When rethrowing an exception, you should do it by simply calling ``++throw;++`` and not ``++throw exc;++``, because the stack trace is reset with the second syntax, making debugging a lot harder.
|
|
|
|
|
|
=== Noncompliant code example
|
|
|
|
[source,csharp]
|
|
----
|
|
try
|
|
{}
|
|
catch(ExceptionType1 exc)
|
|
{
|
|
Console.WriteLine(exc);
|
|
throw exc; // Noncompliant; stacktrace is reset
|
|
}
|
|
catch (ExceptionType2 exc)
|
|
{
|
|
throw new Exception("My custom message", exc); // Compliant; stack trace preserved
|
|
}
|
|
----
|
|
|
|
|
|
=== Compliant solution
|
|
|
|
[source,csharp]
|
|
----
|
|
try
|
|
{}
|
|
catch(ExceptionType1 exc)
|
|
{
|
|
Console.WriteLine(exc);
|
|
throw;
|
|
}
|
|
catch (ExceptionType2 exc)
|
|
{
|
|
throw new Exception("My custom message", exc);
|
|
}
|
|
----
|
|
|
|
|
|
ifdef::env-github,rspecator-view[]
|
|
|
|
'''
|
|
== Implementation Specification
|
|
(visible only on this page)
|
|
|
|
=== Message
|
|
|
|
Use "throw;" instead of "throw xxx;" to preserve the stack trace.
|
|
|
|
|
|
=== Highlighting
|
|
|
|
The whole "throw exc;" statement
|
|
|
|
|
|
'''
|
|
== Comments And Links
|
|
(visible only on this page)
|
|
|
|
=== on 8 Dec 2015, 09:14:18 Tamas Vajk wrote:
|
|
\[~ann.campbell.2] LGTM
|
|
|
|
=== on 26 Jul 2016, 17:50:15 Tamas Vajk wrote:
|
|
\[~ann.campbell.2] I don't think this is a bug.
|
|
|
|
=== on 27 Jul 2016, 13:30:00 Freddy Mallet wrote:
|
|
Agreed [~tamas.vajk] and this is the limit of the usage of this "Bug" issue type because this is really a "Reliability" issue that might prevent someone in production to understand an unexpected behavior as the root cause of the issue is lost. That's why we're classifying this issue as a bug. cc [~ann.campbell.2]
|
|
|
|
endif::env-github,rspecator-view[]
|