programing

Python: 원트라이 멀티 예외

randomtip 2022. 9. 5. 22:40
반응형

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

반응형