파이썬에서 예외를 처리하는 가장 간단한 방법은 "try-except" 블록을 사용하는 것입니다.
예시
try:
fob = open("test.txt", "r")
fob.write("This is my test file for exception handling!!")
except IOError:
print "Error: can\'t find the file or read data"
else:
print "Write operation is performed successfully on the file"
fob.close() 출력
Error: can't find the file or read data