我收到“ TypeError:异常必须从BaseException派生”即使我定义了它 [英] I get "TypeError: exceptions must derive from BaseException" even though I did define it

查看:2054
本文介绍了我收到“ TypeError:异常必须从BaseException派生”即使我定义了它的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

according to python documents, Exception is derived from BaseExceptions and I should use it for user defined exceptions. so I have:

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)

但是我得到了(引用段):

but I get (trackback snippet):

   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

Note: I am converting code from python 27 to 32

推荐答案

我要做:

raise visa_exceptions.VisaIOError(status)

这篇关于我收到“ TypeError:异常必须从BaseException派生”即使我定义了它的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆