gpt4 book ai didi

python - 我得到 "TypeError: exceptions must derive from BaseException"即使我确实定义了它

转载 作者:太空狗 更新时间:2023-10-29 21:03:35 29 4
gpt4 key购买 nike

根据 python 文档,Exception 派生自 BaseExceptions,我应该将它用于用户定义的异常。所以我有:

class VisaIOError(Exception):

def __init__(self, error_code):
abbreviation, description = _completion_and_error_messages[error_code]
Error.__init__(self, abbreviation + ": " + description)
self.error_code = error_code

 raise(visa_exceptions.VisaIOError, status)

但我得到(引用摘要):

   File "C:\Python32\Lib\site-packages\pyvisa\vpp43.py", line 400, in check_status

raise(visa_exceptions.VisaIOError, status)
TypeError: exceptions must derive from BaseException

注意:我正在将代码从 python 27 转换为 32

最佳答案

我必须做的:

raise visa_exceptions.VisaIOError(status)

关于python - 我得到 "TypeError: exceptions must derive from BaseException"即使我确实定义了它,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17819353/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com