
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.
66 lines
1.1 KiB
Plaintext
66 lines
1.1 KiB
Plaintext
== Why is this an issue?
|
|
|
|
When multiple, adjacent ``++try++`` statements have duplicate ``++catch++`` and/or ``++finally++`` blocks, they should be merged to consolidate the ``++catch/finally++`` logic for cleaner, more readable code. Note that this applies even when there is intervening code outside any ``++try++`` block.
|
|
|
|
|
|
=== Noncompliant code example
|
|
|
|
[source,text]
|
|
----
|
|
try
|
|
{
|
|
DoTheFirstThing(a, b);
|
|
}
|
|
catch (InvalidOperationException ex)
|
|
{
|
|
HandleException(ex);
|
|
}
|
|
|
|
DoSomeOtherStuff();
|
|
|
|
try // Noncompliant; catch is identical to previous
|
|
{
|
|
DoTheSecondThing();
|
|
}
|
|
catch (InvalidOperationException ex)
|
|
{
|
|
HandleException(ex);
|
|
}
|
|
|
|
try // Compliant; catch handles exception differently
|
|
{
|
|
DoTheThirdThing(a);
|
|
}
|
|
catch (InvalidOperationException ex)
|
|
{
|
|
LogAndDie(ex);
|
|
}
|
|
----
|
|
|
|
|
|
=== Compliant solution
|
|
|
|
[source,text]
|
|
----
|
|
try
|
|
{
|
|
DoTheFirstThing(a, b);
|
|
DoSomeOtherStuff();
|
|
DoTheSecondThing();
|
|
}
|
|
catch (InvalidOperationException ex)
|
|
{
|
|
HandleException(ex);
|
|
}
|
|
|
|
try // Compliant; catch handles exception differently
|
|
{
|
|
DoTheThirdThing(a);
|
|
}
|
|
catch (InvalidOperationException ex)
|
|
{
|
|
LogAndDie(ex);
|
|
}
|
|
----
|
|
|