1.try...except...:是Python里面错误类型抛出异常检测,当try里面的语句报错的时候,执行except。在编写代码的时候,可以有效避免因为不可预知的错误导致程序报错。
2.在except后面通常可以选择出错误类型的基类,可以精准定位,如果错误类型是未知的话,一般使用exception抛出常规错误类型基类。
try: a = 9 total = a + 1 except Exception as e: print(e)
3.try...except...else...:指的是,当执行try的代码块时,如果不报异常则执行。
4.try...except...else...finally:指的是,当执行try的代码块时,无论是否发生异常都将执行。
抛出异常的类别:
https://docs.python.org/3/c-api/exceptions.html#exception-objects
- quot python-try 文件 python exceptquot python-try文件python python-try quot exception rabbitmq reason outofmemoryerror quot exception thread messagingexception quot exception connect bindingexception quot exception statement version unsupportedclassversionerror quot exception illegalcharactererror quot content-box exceptions noclassdeffounderror quot serverfactory exception quot installation exception occurred