Python “如何不拥有”;在处理上述异常的过程中,发生了另一个异常:";在定义自己的异常类时?
基本上,我定义了一个新的异常类Python “如何不拥有”;在处理上述异常的过程中,发生了另一个异常:";在定义自己的异常类时?,python,class,exception,try-catch,raise,Python,Class,Exception,Try Catch,Raise,基本上,我定义了一个新的异常类 class DirectoryError(FileNotFoundError): pass 这个类是python中已经存在的更一般的错误类FileNotFoundError的一部分 在我的代码中,我正在尝试以下内容: try : shutil.copy(dir,dir) except FileNotFoundError: raise DirectoryError("not the good directory") 但是python
class DirectoryError(FileNotFoundError):
pass
这个类是python中已经存在的更一般的错误类FileNotFoundError的一部分
在我的代码中,我正在尝试以下内容:
try :
shutil.copy(dir,dir)
except FileNotFoundError:
raise DirectoryError("not the good directory")
但是python告诉我有两次错误,一次是FileNotFound错误消息,然后在说“在处理上述异常期间,发生了另一个异常:”之后,它再次告诉我错误,这次是DirectoryError消息
如何仅显示错误消息,而不同时显示两者?查看此答案:查看此答案: