반응형
Python: 원트라이 멀티 예외
Python 에서는, 멀티를 가지는 것이 가능합니까?except
자신을 위한 진술서try
스테이트먼트?예를 들어 다음과 같습니다.
try:
#something1
#something2
except ExceptionType1:
#return xyz
except ExceptionType2:
#return abc
네, 가능합니다.
try:
...
except FirstException:
handle_first_one()
except SecondException:
handle_second_one()
except (ThirdException, FourthException, FifthException) as e:
handle_either_of_3rd_4th_or_5th()
except Exception:
handle_all_other_exceptions()
참조: http://docs.python.org/tutorial/errors.html
"as" 키워드는 에러를 변수에 할당하기 위해 사용되며, 에러는 나중에 코드에서 자세히 조사할 수 있습니다.또한 python 3에서는 트리플 예외 케이스의 괄호가 필요합니다.이 페이지에는 더 많은 정보가 있습니다. 한 줄에 여러 예외를 포착합니다(블록 제외).
언급URL : https://stackoverflow.com/questions/6095717/python-one-try-multiple-except
반응형
'programing' 카테고리의 다른 글
MariaDB Connector/J 및 AWS RDS Aurora에서 이상한 간헐적 문제 발생 (0) | 2022.09.05 |
---|---|
MySQL DATE_FORMAT 또는 DateTime.strftime을 통한 DateTime 문자열 (0) | 2022.09.05 |
POST 데이터를 사용한 PHP 리다이렉트 (0) | 2022.09.05 |
iOS Safari 개인 브라우징 모드에서 Laravel 쿠키가 설정되지 않음 (0) | 2022.09.05 |
정수 인덱스로 팬더 시리즈/데이터프레임 행 선택 (0) | 2022.09.05 |