- 필수 기능
- 앱 내
- 서비스 관리
- 인프라스트럭처
- 애플리케이션 성능
- 디지털 경험
- 소프트웨어 제공
- 보안
- 로그 관리
- 관리
- 인프라스트럭처
- ci
- containers
- csm
- ndm
- otel_guides
- overview
- slos
- synthetics
- tests
- 워크플로
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