
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.
71 lines
1.5 KiB
Plaintext
71 lines
1.5 KiB
Plaintext
== Why is this an issue?
|
|
|
|
A ``++Catch++`` clause that only rethrows the caught exception has the same effect as omitting the ``++Catch++`` altogether and letting it bubble up automatically, but with more code and the additional detriment of leaving maintainers scratching their heads.
|
|
|
|
|
|
Such clauses should either be eliminated or populated with the appropriate logic.
|
|
|
|
=== Noncompliant code example
|
|
|
|
[source,vbnet]
|
|
----
|
|
Dim s As String = ""
|
|
Try
|
|
s = File.ReadAllText(fileName)
|
|
Catch e As Exception
|
|
Throw
|
|
End Try
|
|
----
|
|
|
|
=== Compliant solution
|
|
|
|
[source,vbnet]
|
|
----
|
|
Dim s As String = ""
|
|
Try
|
|
s = File.ReadAllText(fileName)
|
|
Catch e As Exception
|
|
logger.LogError(e)
|
|
Throw
|
|
End Try
|
|
----
|
|
or
|
|
|
|
[source,vbnet]
|
|
----
|
|
Dim s As String = File.ReadAllText(fileName)
|
|
----
|
|
|
|
=== Exceptions
|
|
|
|
This rule will not generate issues for ``++Catch++`` blocks with just ``++Throw++`` inside if they are followed by a ``++Catch++`` block for a more general exception type that does more than just rethrowing the exception.
|
|
|
|
|
|
[source,vbnet]
|
|
----
|
|
Dim s As String = ""
|
|
Try
|
|
s = File.ReadAllText(fileName)
|
|
Catch e As IOException 'Compliant, if removed will change the logic
|
|
Throw
|
|
Catch e As Exception 'Compliant, does more than just rethrow
|
|
logger.LogError(e)
|
|
Throw
|
|
End Try
|
|
----
|
|
|
|
ifdef::env-github,rspecator-view[]
|
|
|
|
'''
|
|
== Implementation Specification
|
|
(visible only on this page)
|
|
|
|
include::../message.adoc[]
|
|
|
|
'''
|
|
== Comments And Links
|
|
(visible only on this page)
|
|
|
|
include::../comments-and-links.adoc[]
|
|
endif::env-github,rspecator-view[]
|