Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我正在编写一个通过 ftp 连接到我的网站的程序。如果登录身份验证失败,我希望它继续做其他事情。但是验证失败错误会自动退出程序。有没有办法忽略这一点并继续?
您可以使用 Python 的异常处理:
try: do_something() except Exception, ex: print "The process failed because", ex do_something_else()
将 do_something() 替换为您首先要尝试的代码。当 do_something() 部分失败时,将 do_somthing_else() 代码替换为您希望尝试的代码
异常处理参考