3 回答
慕神8447489
TA贡献1780条经验 获得超1个赞
shutil.rmtreeOSError:
>>> 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)
Exceptionexcept:
SystemExitsys.exit()
>>> try: ... sys.exit(1) ... except: ... pass ... >>>
>>> try: ... sys.exit(1) ... except Exception: ... pass ... shell:~$
OSErrorErrno 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 errnoifif 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
提交
取消
