Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 499
Siavash Avatar asked Jul 23 '13 19:07

Siavash


People also ask

What is BaseException in Python?

The BaseException is the base class of all other exceptions. User defined classes cannot be directly derived from this class, to derive user defied class, we need to use Exception class. The Python Exception Hierarchy is like below. BaseException.

What is TypeError Exception?

Type Error Exception is raised when two different or unrelated types of operands or objects are combined. In the below example, an integer and a string are added, which results in a type error. try: a = 5 b = "DataCamp" c = a + b except TypeError: print ('TypeError Exception Raised') else: print ('Success, no error!

What is raise ValueError in Python?

What is Python ValueError? Python ValueError is raised when a function receives an argument of the correct type but an inappropriate value. Also, the situation should not be described by a more precise exception such as IndexError.

What is except Exception as e?

In contrast, the except Exception as e statement is a statement that defines an argument to the except statement. e in the latter statement is utilized to create an instance of the given Exception in the code and makes all of the attributes of the given Exception object accessible to the user.


1 Answers

I have to do :

raise visa_exceptions.VisaIOError(status)
like image 132
Siavash Avatar answered Oct 05 '22 08:10

Siavash