mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-29 13:25:17 +00:00
66 lines
1.3 KiB
Python
66 lines
1.3 KiB
Python
"""
|
|
Violation:
|
|
|
|
Checks for `raise` statements within `try` blocks.
|
|
"""
|
|
class MyException(Exception):
|
|
pass
|
|
|
|
|
|
def bad():
|
|
try:
|
|
a = process()
|
|
if not a:
|
|
raise MyException(a)
|
|
|
|
raise MyException(a)
|
|
|
|
try:
|
|
b = process()
|
|
if not b:
|
|
raise MyException(b)
|
|
except Exception:
|
|
logger.exception("something failed")
|
|
except Exception:
|
|
logger.exception("something failed")
|
|
|
|
|
|
def bad():
|
|
try:
|
|
a = process()
|
|
if not a:
|
|
raise MyException(a)
|
|
|
|
raise MyException(a)
|
|
|
|
try:
|
|
b = process()
|
|
if not b:
|
|
raise MyException(b)
|
|
except* Exception:
|
|
logger.exception("something failed")
|
|
except* Exception:
|
|
logger.exception("something failed")
|
|
|
|
|
|
def good():
|
|
try:
|
|
a = process() # This throws the exception now
|
|
except MyException:
|
|
logger.exception("a failed")
|
|
except Exception:
|
|
logger.exception("something failed")
|
|
|
|
|
|
def fine():
|
|
try:
|
|
a = process() # This throws the exception now
|
|
finally:
|
|
print("finally")
|
|
|
|
|
|
def fine():
|
|
try:
|
|
raise ValueError("a doesn't exist")
|
|
except TypeError: # A different exception is caught
|
|
print("A different exception is caught")
|