我有一个无法引发任何异常的 try/except 块。该块简单如下:
try:
os.system("notepad+ "+out_file_path)
except SomeException:
print("Make sure you have notepad+ in your %PATH% and try again")
请注意,我故意使用“notepad+”(不存在)来导致异常。
我在上述代码中尝试将 ( OSError
、RuntimeError
和) 作为“SomeException” OSError(winerror)
,但是无论如何我都无法打印出消息,并且在所有情况下,这都是我收到的:Exception
'notepad+' is not recognized as an internal or external command,
operable program or batch file.
我想知道这样的系统错误是否可以覆盖所有异常(即不会被捕获)或者我应该做些什么来让我的代码按照我想要的方式工作。