Notice
Recent Posts
Recent Comments
Link
«   2025/08   »
1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
31
Tags
more
Archives
Today
Total
관리 메뉴

노승현

python - 예외처리 본문

Python

python - 예외처리

nsh95 2024. 5. 13. 17:03

예외처리 : 프로그램을 비정상 종료 시키지 않기 위해 예외처리

 데이터 가공 작업 중에 에러, 예외 등이 발생
 1) 무시하고 계속 2) 처리
 어떠한 데이터가 입력되어도
 전체 프로그램은 멈춰서는 안된다.

 

 

try:
    print('a')
    num=10/1
    print('num = '+str(num))
    print('b')

except ZeroDivisionError:
    print('c')
except Exception as msg :
    print('예외발생 : ',end='')
    print(msg)
else:
    # 파이썬에서는 try 를 if 메커니즘으로 구현 else 가능
    print('예외가 발생하지 않았을 때 출력')
finally:
    print('항상 출력')

 

 

 

 

'Python' 카테고리의 다른 글

python - 다양한 그래프 그려보기  (0) 2024.05.23
python - 데이터 가공  (0) 2024.05.10
python - 파일 입출력  (0) 2024.05.08
UP & DOWN 게임 (python)  (0) 2024.05.03
python - 함수와 메서드  (1) 2024.05.03