This product is not supported for your selected
Datadog site. (
).
메타데이터
ID: python-best-practices/generic-exception-last
언어: 파이썬(Python)
심각도: 알림
범주: 모범 사례
설명
여러 예외를 찾을 때 제네릭 Exception
을 맨 마지막으로 찾아야 합니다. Exception
은 매우 포괄적이므로 특정 예외 앞에 놓으면 모든 예외를 찾으며, 특정 예외 핸들러는 찾지 않습니다.
이러한 이유로 제네릭 Exception
은 특정 예외 핸들러가 트리거 및 실행될 수 있도록 마지막에 처리되어야 합니다.
자세히 알아보기
비준수 코드 예
try:
pass
except Exception:
pass
except FileNotFound as e:
pass
준수 코드 예
try:
pass
except MyError:
pass
except Exception as e:
pass
try:
pass
except MyError:
pass
except FileNotFound as e:
pass