We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
bad-exception-context
1 parent 0227e7f commit e41b2f0Copy full SHA for e41b2f0
3 files changed
doc/data/messages/b/bad-exception-context/bad.py
@@ -0,0 +1,7 @@
1
+def divide(x, y):
2
+ result = 0
3
+ try:
4
+ result = x / y
5
+ except ZeroDivisionError:
6
+ raise ValueError(f"Division by zero when dividing {x} by {y} !") from result # [bad-exception-context]
7
+ return result
doc/data/messages/b/bad-exception-context/good.py
+ except ZeroDivisionError as exc:
+ raise ValueError(f"Division by zero when dividing {x} by {y} !") from exc
doc/data/messages/b/bad-exception-context/related.rst
@@ -0,0 +1,2 @@
+- `The raise statement <https://docs.python.org/3/reference/simple_stmts.html#the-raise-statement>`_
+- `Explicit Exception Chaining <https://peps.python.org/pep-3134/#explicit-exception-chaining>`_ per PEP 3134
0 commit comments