Skip to content

Instantly share code, notes, and snippets.

@weihanchen
Created September 15, 2023 11:43
Show Gist options
  • Save weihanchen/8fd4343be76556191d427faec150612c to your computer and use it in GitHub Desktop.
Save weihanchen/8fd4343be76556191d427faec150612c to your computer and use it in GitHub Desktop.
def try_except_finally_example():
try:
num1 = int(input("請輸入一個整數: "))
num2 = int(input("請輸入另一個整數: "))
result = num1 / num2
except ZeroDivisionError:
print("錯誤:除以零。")
except ValueError:
print("錯誤:輸入的不是整數。")
finally:
print("不管是否發生異常,這裡都會執行。")
try_except_finally_example()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment