2019-01-25 异常捕捉

while True:
try:
num1 = int(input("Enter the first number:"))
num2 = int(input("Enter the second number:"))
print(num1/num2)
break
except Exception as err:
print("Something went wrong!")
print(err)

try-except 捕捉异常,print(err)可以把异常情况打印出来

break 终止循环,while True可以一直执行循环

你可能感兴趣的:(2019-01-25 异常捕捉)