11

根据 python 文档,异常是从 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

4

1 回答 1

10

我要做 :

raise visa_exceptions.VisaIOError(status)
于 2013-07-23T19:32:27.953 回答