# 아래 코드는 sigint같은 키보드 인터럽트도 처리해버립니다
# case 1
try:
do_something()
except:
print "잡았다!"
# case 2
# 모든 예외를 한꺼번에 처리하는 코드는 파이썬에서 권장하지는 않습니다
# 아래같이 except안에서 또 raise 해준다면 괜찮습니다
try:
do_something()
except:
raise
# 로깅이 필요할 경우
# case 3
import traceback
import logging
try:
do_something()
except Exception as e:
logging.error(traceback.format_exc()) #로깅
아래는 최신 공식 문서로 링크 걸어둡니다
https://docs.python.org/3/tutorial/errors.html
8. Errors and Exceptions — Python 3.8.6 documentation
8. Errors and Exceptions Until now error messages haven’t been more than mentioned, but if you have tried out the examples you have probably seen some. There are (at least) two distinguishable kinds of errors: syntax errors and exceptions. 8.1. Syntax Er
docs.python.org