Python 3中未捕获异常
我有一个try/except块,我不能为其引发任何异常。该模块简单如下所示:Python 3中未捕获异常,python,python-3.x,exception,system-error,Python,Python 3.x,Exception,System Error,我有一个try/except块,我不能为其引发任何异常。该模块简单如下所示: try: os.system("notepad+ "+out_file_path) except SomeException: print("Make sure you have notepad+ in your %PATH% and try again") 请注意,我故意使用“记事本+”(不存在)来引起异常 我在上述代码中尝试(OSError,RuntimeError,OSError(winerro
try:
os.system("notepad+ "+out_file_path)
except SomeException:
print("Make sure you have notepad+ in your %PATH% and try again")
请注意,我故意使用“记事本+”(不存在)来引起异常
我在上述代码中尝试(OSError
,RuntimeError
,OSError(winerror)
和Exception
)作为“SomeException”,但无论如何我都无法打印消息,在所有情况下我都会收到:
'notepad+' is not recognized as an internal or external command,
operable program or batch file.
我想知道这样的系统错误是否可以覆盖所有异常(即未被捕获),或者我应该做些什么来让我的代码以我想要的方式工作。您无法捕获该异常。我的建议是切换到
子流程
。它更健壮。话虽如此,如果您确实需要使用os.system
,您必须检查os.system
的返回码是否为非零值。非常感谢。这正是我要找的!