try문으로 예외가 발생할 가능성이 있는 코드를 작성하고, except문으로 예외 거르기!
else문은 예외가 발생하지 않는 경우 출력되며, finally는 예외 발생여부와 관련없이 항상 출력된다!
Code Example🙄 :
try:
print('10'+10);
except IOError:
print('You have an input/output error')
except TypeError:
print('You are using the wrong data types!')
except: #모든 error
print("Hey you got an error!")
else: #예외가 실행되지 않는 경우
print("Else Bock run")
finally: #항상 실행
print("Finally will always run, error or no errors!")
def divider(a,b):
try:
return a/b;
except ZeroDivisionError:
print('Please do not divide by zero!');
divider(1,0);
# You are using the wrong data types!
# Finally will always run, error or no errors!
# Please do not divide by zero!
'Python🍍' 카테고리의 다른 글
Python Lambda🍋 (0) | 2022.06.27 |
---|---|
Python Function✨ (0) | 2022.06.27 |
Python 반복문 while, for⚡ (0) | 2022.06.27 |
Python 조건문 If🙄 (0) | 2022.06.27 |
Python Operators👀 (0) | 2022.06.25 |