
Co-authored-by: Amélie Renard <44666826+amelie-renard-sonarsource@users.noreply.github.com> Co-authored-by: Dorian Burihabwa <75226315+dorian-burihabwa-sonarsource@users.noreply.github.com>
41 lines
750 B
Plaintext
41 lines
750 B
Plaintext
== Why is this an issue?
|
|
|
|
An `except` clause that only rethrows the caught exception has the same effect as omitting the `except` altogether and letting it bubble up automatically.
|
|
|
|
[source,python]
|
|
----
|
|
a = {}
|
|
try:
|
|
a[5]
|
|
except KeyError:
|
|
raise # Noncompliant
|
|
----
|
|
|
|
Such clauses should either be removed or populated with the appropriate logic.
|
|
|
|
[source,python]
|
|
----
|
|
a = {}
|
|
try:
|
|
a[5]
|
|
except KeyError as e:
|
|
logging.exception('error while accessing the dict')
|
|
raise e
|
|
----
|
|
|
|
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[]
|