본문 바로가기
SW 프로그래밍/파이썬

예외처리 try except

by N2info 2020. 3. 26.
>>> retval = 10/0
Traceback (most recent call last):
  File "<pyshell#0>", line 1, in <module>
    retval = 10/0
ZeroDivisionError: division by zero
>>> try:
	retval = 10/0
	except ZeroDivisionError as e:
		
SyntaxError: invalid syntax
>>> try:
	retval = 10/0
except ZeroDivisionError as e:
	print(e)

	
division by zero
>>> 

참고 : https://jink1982.tistory.com/53?category=648862

모든 에러에 대한...

>>> try:
	sum = val[0] + val[1]
except Exception as e:
	print(e)
finally:
	print(1)

	
name 'val' is not defined
1
>>> 

참고 : http://pythonstudy.xyz/python/article/20-%EC%98%88%EC%99%B8%EC%B2%98%EB%A6%AC