根据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)
但是我得到了(trackback代码段):
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
答案 0 :(得分:5)
我必须这样做:
raise visa_exceptions.VisaIOError(status)