python基础教程笔记(chapt.8) 异常

常见内建异常

创建异常:
class SomeCustomException(Exception): pss

捕捉异常

x=input('Enter the first number: ')
y=input('Enter the second number: ')
print x/y
##################
try:
    x=input('Enter the first number: ')
    y=input('Enter the second number: ')
    print x/y
except ZeroDivisionError:
    print "The second number can't be zero!"

你可能感兴趣的:(python基础教程笔记(chapt.8) 异常)