글

라벨이 exception인 게시물 표시

[Python] Python의 예외 처리 (try~except)

Python의 예외처리 (try~except) 하기 try:     a= int(input('int1'))     b= int(input('int2'))     print('a/b=',a/b)     a=[1,2]     print(a[3]) except Exception as e:     pass # 특정 에러발생할 경우 통과          # 오류 회피하기 #finally 에러와 상관없이 무조건 실행하기 위한 키워드 finally:     print('무조건 실행하는 부분') #예외를 강제로 발생시키는 경우 #raise 명령어를 사용한다. def rsp(a,b):     str1 = ['R','S','P']     if a not in str1:         raise ValueError         if b not in str1:         raise ZeroDivisionError try:     rsp('R','Se') except ValueError:     print('Wrong value') #반복문 #StopIteration school ={'1':[1,2,3,4,5],          '2':[5,4,7,8,1]} #7이 넘는 학새을 발견하면 반복을 종료 #예외 발생 시키기 #1,2 7이 넘는 학생이 존재한다. try:     for num,stu in school.items():         for i ...