4.12 예외 만들기

class UppercaseException(Exception):
pass
words = ['eeenie', 'meenie', 'miny', 'MO']
for word in words:
if word.isupper():
raise UppercaseException(word)

UppercaseException Traceback (most recent call last)
<ipython-input-9-56dc8d092fd2> in <module>()
2 for word in words:
3     if word.isupper():
----> 4         raise UppercaseException(word)
UppercaseException: MO

우리는 필요한 예외 처리를 선택해서 사용할 수 있다. 예외 타입을 정해서 특별한 상황에서의 예외를 처리 할 수 있다.

Comments