모든 예외처리
예외 처리 방식 1.
try:
except:
print('Exception Handling')
예외 처리 방식 2.
try:
except Except:
print('Exception Handling')
예외 처리 방식 3.
try:
except:
print('Exception Handling')
except <Exception 종류 1>:
print('Exception 1 occured')
except <Exception 종류 2>:
print('Exception 2 occured')
else:
finally:
항상 실행
예외 처리 방식 4.
try:
Error 발생 가능 지역
except Exception as e:
print(e)
- SyntaxError, TypeError, NameError, IndexError, ValueError, KeyError...
SyntaxError: 문법 오류
if True
pass
TypeError
a = 10
b = 15
print(C)
ZeroDivisionError
print( 100/0 )
IndexError
a = [1,2,3,4,5]
print(a[100])
KeyError
a = { 'name': 'Lee' }
print(a['age'])
AttributeError
import time
print(time.time2())
ValueError
x = [10, 50, 90]
x.remove(50)
FileNotFoundError
f = open('test.txt', 'r')
TypeError
os.path.exists() 익셉션
raise: 익셉션 발생
fileno, filename
from inspect import currentframe, getframeinfo
frameinfo = getframeinfo(currentframe())
print(frameinfo.filename, frameinfo.lineno)
=======================================
from inspect import currentframe, getframeinfo
def debugPrint(frameinfo):
print("file: {} line: {}".format(frameinfo.filename,frameinfo.lineno))
debugPrint(getframeinfo(currentframe()))