Errors are errors in the system that cannot be changed and handled by the programmer, such as system crashes, insufficient memory space, and method call stack overflow. Encountered such an error, it is recommended to terminate the program.
Exception means an exception that the program can handle, which can be caught and possibly recovered. When encountering such an exception, the exception should be handled as much as possible to make the program run again, and the exception should not be terminated at will.
"""
异常处理机制:
else:没有异常时执行的内容
finally:总会执行的内容
"""try:
a=1print(b)except NameError as e :print('0-name error')except KeyError as e :print('4-key error')except Exception as e:print('1-exception')else:print('2-noerror')finally:print('3-run code')##结果0-name error
3-run code