python raise & assert
def CheckValue(value): value = int(value) #assert condiction, expression #当 condition为True的时候,程序不会assert,当condition判断的条件为False时候,程序就会assert assert value>0, "你输入的值小于0,出现错误,程序中断(assert)" print("程序正常运行") return value+1 CheckValue(8)
程序正常运行
name = 2 if name == 1: print("yes") else: raise Exception("error")
error