3 回答

慕神8447489
TA贡献1780条经验 获得超1个赞
shutil.rmtree
OSError
:
>>> shutil.rmtree("/fake/dir") Traceback (most recent call last): [...] OSError: [Errno 2] No such file or directory: '/fake/dir'
try: shutil.rmtree(path) except OSError: pass
shutil.rmtree(2)
Exception
except:
SystemExit
sys.exit()
>>> try: ... sys.exit(1) ... except: ... pass ... >>>
>>> try: ... sys.exit(1) ... except Exception: ... pass ... shell:~$
OSError
Errno 2
try: shutil.rmtree(path) except OSError, e: if e.errno == 2: # suppress "No such file or directory" error pass else: # reraise the exception, as it's an unexpected error raise
import errno
if
if e.errno == errno.ENOENT:

HUH函数
TA贡献1836条经验 获得超4个赞
当您只想在不处理异常的情况下执行TRY CATCH时,如何在Python中执行呢?
try: do_something() except: handle_exception() raise #re-raise the exact same exception that was thrown
添加回答
举报
0/150
提交
取消