예외의 종류

CODEDRAGON Development/Python

반응형


 

 

예외의 종류

NameError

·       선언하지 않은 변수 'x'에 접근

·       NameError: name 'x' is not defined

 

 

 

 

 

ZeroDivisionError

·       '0'으로 나눔

·       ZeroDivisionError: division by zero

 

 

 

 

 

IndexError

·       리스트의 접근 가능한 인덱스를 넘음

·       시퀀스 자료형이 범위를 벗어난 인덱스 참조 요구시에 발생시킴

·       리스트, 튜플, 문자열등에서도 동일한 조건에서 발생됨

·       IndexError: list index out of range

 

 

 

 

 

TypeError

·       지원하지 않는 연산(정수를 문자열로 나눔)

·       TypeError: unsupported operand type(s) for /: 'int' and 'str'

 

 

 

 

 

ValueError

·       입력받은 문자열 숫자를 숫자자료형인 int float 변환할 없을 발생됩니다.

·       , 숫자로 변환할 없는 문자열을 변환하려고 할때 발생합니다.

·       ValueError: invalid literal for int() with base 10: 'a1000'

 


반응형

'Development > Python' 카테고리의 다른 글

__init__.py  (0) 2020.03.11
Exception 계층도 (Exception hierarchy)  (0) 2020.03.11
shutil 모듈  (0) 2020.03.10
types  (0) 2020.03.10
tempfile  (0) 2020.03.10