https://www.runoob.com/python/python-exceptions.html

1. 附自己学习成果:

#取四件商品价格总和减去最便宜的商品价格的数  
import sys  
def addlist():  
try:  
list.append(geterror(int(input())))  
except ValueError:  
print("错误!输入的值不为数字")  
sys.exit()  
def geterror(raw_input):  
try:  
if raw_input < 0:  
raise ValueError  
except ValueError:  
print("错误!输入的值不为正数")  
sys.exit()  
else:  
return(raw_input)  
list = []  
print("请分别输入四件商品价格")  
print("第一件:")  
addlist()  
print("第二件:")  
addlist()  
print("第三件:")  
addlist()  
print("第四件:")  
addlist()  
Min = min(list)  
Sum = 0  
for i in range(len(list)):  
Sum = Sum + list[i]  
result = Sum - Min  
print("总价为:",result)

2. int()常常为了避免报错,搭配try…except ValueError