do not raise base exception

이 페이지는 아직 한국어로 제공되지 않으며 번역 작업 중입니다. 번역에 관한 질문이나 의견이 있으시면 언제든지 저희에게 연락해 주십시오.

Metadata

ID: python-best-practices/no-base-exception

Language: Python

Severity: Notice

Category: Best Practices

Description

Do not raise Exception and BaseException. These are too generic. Having generic exceptions makes it difficult to differentiate errors in a program. Use a specific exception, for example, ValueError, or create your own instead of using generic ones.

Learn More

Non-Compliant Code Examples

if foo:
	raise Exception("bla")
elif bar:
	raise Exception
else:
	raise Exception
def use_base_exception():
	raise Exception
	raise Exception("awesome")
for v in list:
	raise BaseException

Compliant Code Examples

if foo:
	print("bar")
else:
	raise ValueError
https://static.datadoghq.com/static/images/logos/github_avatar.svg https://static.datadoghq.com/static/images/logos/vscode_avatar.svg jetbrains

Seamless integrations. Try Datadog Code Analysis