简体   繁体   中英

I get “TypeError: exceptions must derive from BaseException” even though I did define it

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

And

 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

Note: I am converting code from python 27 to 32

我要做 :

raise visa_exceptions.VisaIOError(status)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM