• Register
0 votes
4.1k views

Problem :

When I try to run the below code:

j=0
while j<5:
    j=j+1;
    try:
        MySellSta=client.get_order(symbol=MySymb,orderId=MySellOrderNum,recvWindow=MyDelay)
    except client.get_order as mye:
        print ("This is the error message!{}".format(j))
#End while

I got the following error: TypeError: catching classes that do not inherit from BaseException is not allowed

I kind of fix it with the below code:

j=0
while j<5:
    j=j+1;
    try:
        MySellSta=client.get_order(symbol=MySymb,orderId=MySellOrderNum,recvWindow=MDelay)
    except:
        print ("This is the error message!{}".format(i))
#End while

The result is that it ignores my error and go to my next while but I want to catch my error and print my error.

7.5k points

Please log in or register to answer this question.

1 Answer

0 votes

Solution :

The above mentioned error usually occurs because in your exception clause you must indicate which exception you want to capture. An exception is your class that inherits directly or indirectly from your base class Exception.

Instead I have put the client.get_order where the python expected your name of the exception, but what you have put is the method of the object, and not the class that inherits from the Exception.

The solution is as below :

try:
    MySellSta=client.get_order(symbol=MySymb,orderId=MySellOrderNum,recvWindow=MyDelay)
except Exception as mye:
    if mye.code==-2013:
        print ("The Order does not exist.");
    elif mye.code==-2014:
        print ("The API-key format is invalid.");
    #End If

 

I hope the solution solves fixes your issues.

38.6k points

Related questions

0 votes
1 answer 114 views
114 views
Problem: I tried my best to solve this situation but it didnt work! any help! Typeerror: catching classes that do not inherit from baseexception is not allowed.
asked Mar 7 Wafa Abu Yousef 6.1k points
0 votes
1 answer 143 views
143 views
Problem: I got this error:TypeError: catching classes that do not inherit from BaseException is not allowed. The result it's that ignores the error and go to the next while but I want to catch the error and print it.
asked May 2 sumaiya simi 43.9k points
0 votes
1 answer 14 views
14 views
Problem: As I previously stated in my question, I am having difficulty learning. Could someone help assist me in completing my project?
asked Mar 30 tuhin1 48.9k points
0 votes
1 answer 442 views
442 views
Problem: What's wrong with the following code (under Python 2.7.1): class TestFailed(BaseException): def __new__(self, m): self.message = m def __str__(self): return self.message try: raise TestFailed('Oops') except TestFailed as x: print x
asked Feb 21 Mashhoodch 13k points
0 votes
1 answer 16 views
16 views
Problem: Typeerror: exceptions must derive from baseexception.
asked Jun 26 Shima 126k points
0 votes
1 answer 61 views
61 views
Problem: I'm not sure how I got this : Typeerror: argument of type 'type' is not iterable?
asked May 22 Florina Gulnar 106k points
1 vote
1 answer 31 views
31 views
Problem: Would any body like to comment on this ? Is it possible to store multiple data types in system.array.
asked Apr 25 PkGuy 25.9k points
0 votes
1 answer 4 views
4 views
Question: All classes inherit from java.lang.Object, although extends Object is (generally) not written out anywhere. How is this possible?
asked Apr 12 Atik03 26.5k points
0 votes
1 answer 20 views
20 views
Problem: I created a custom exception class that derives from std::exception. #include <iostream> class Exception : std::exception { public: const char* what() const noexcept override { return "test"; } }; int main() { try { throw Exception(); } catch ( ... this happen? Does catching by reference to base not work? How can I catch all exceptions deriving from std::exception using one catch block?
asked May 1 anika11 32.2k points
0 votes
1 answer 844 views
844 views
Problem : I am getting bellow error while I try to connect MySql database with Java using connector 8.0.11 java.sql.sqlnontransientconnectionexception: public key retrieval is not allowed
asked Oct 19, 2019 peterlaw 6.9k points