rspec/rules/S2737/vbnet/rule.adoc

57 lines
1.3 KiB
Plaintext
Raw Normal View History

2021-01-27 13:42:22 +01:00
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.
2020-06-30 12:48:07 +02:00
2021-02-02 15:02:10 +01:00
2020-06-30 12:48:07 +02:00
Such clauses should either be eliminated or populated with the appropriate logic.
== Noncompliant Code Example
----
Dim s As String = ""
Try
s = File.ReadAllText(fileName)
Catch e As Exception
Throw
End Try
----
== Compliant Solution
----
Dim s As String = ""
Try
s = File.ReadAllText(fileName)
Catch e As Exception
logger.LogError(e)
Throw
End Try
----
or
2020-06-30 12:48:07 +02:00
----
Dim s As String = File.ReadAllText(fileName)
----
== Exceptions
2021-01-27 13:42:22 +01:00
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.
2020-06-30 12:48:07 +02:00
2021-02-02 15:02:10 +01:00
2020-06-30 12:48:07 +02:00
----
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::rspecator-view[]
== Comments And Links
(visible only on this page)
include::../comments-and-links.adoc[]
endif::rspecator-view[]