Python异常-try、raise语句及自定义异常类
一、异常处理语句
#try/except try: pass except: pass try: pass except Exception: pass #try/except ... try: pass except (Exception1, Exception2): pass try: pass except Exception1: pass except Exception2: pass #try/except ... as ... try: pass except Exception as e: isinstance(e, Exception) except ... try: pass except (Exception1, Exception2) as e: print(e) #try/except/else try: pass except ...: pass except ... else: pass #try/finally try: pass finally: pass try: pass except ...: pass finally: pass try: pass except ...: pass except ... else: pass finally: pass
二、自定义异常类
class MyException(Exception): pass
三、显式触发异常
raise raise MyException raise MyException() raise MyException(‘Error‘) raise MyException from None raise MyException() from None
相关推荐
HMHYY 2020-07-28
寻常白昼 2020-08-15
loviezhang 2020-06-16
lsfreeing 2020-06-11
sunlizhen 2020-06-01
Yasin 2020-05-14
czsay 2020-05-09
wqbala 2020-03-04
会哭的雨 2020-02-19
wordmhg 2020-02-13
awoyaoc 2020-02-02
czsay 2020-01-31
xiaoxiaoniaoer 2020-01-29
猛禽的编程艺术 2020-01-16
xinhao 2020-01-14
TinyDolphin 2020-01-14
Winterto0 2020-01-07
lustdevil 2019-12-31
wangyjbk 2019-12-27