-3

im using a stock trading api that throws a exception if a error happens. Write now when i put in the wrong order id i get the following exception

Exception has occurred: APIError
order_id is missing

I have added a try and catch so the exception will not go off in the catch block I dont know how to find out how it happen so it simply displays a message saying "generic error" how could i have it say order_id is missing? code

def isClosed(id):
    global errorMesg
    try:
        y=api.get_order(id)
        if (y.status=="filled"):
           return 1
        return 0
    except:
# how can the below line disply why the exception went off?
        print("generic error") 
    return -1
Brian61354270
  • 8,690
  • 4
  • 21
  • 43
Ted pottel
  • 6,869
  • 21
  • 75
  • 134
  • Does this answer your question? [How to print an exception in Python?](https://stackoverflow.com/q/1483429/2745495) – Gino Mempin Jun 12 '21 at 00:59
  • 1
    There could be other errors not just about order_id, so it's better to log or print the original exception, rather than printing out your own error message. – Gino Mempin Jun 12 '21 at 01:03

1 Answers1

0

Use the following line:

except Exception as e:
    print(e)
DapperDuck
  • 2,728
  • 1
  • 9
  • 21