How to print an exception in Python 3?

前端 未结 7 2107
有刺的猬
有刺的猬 2021-01-31 13:48

Right now, I catch the exception in the except Exception: clause, and do print(exception). The result provides no information since it always prints

7条回答
  •  北恋
    北恋 (楼主)
    2021-01-31 14:46

    I've use this :

    except (socket.timeout, KeyboardInterrupt) as e:
        logging.debug("Exception : {}".format(str(e.__str__).split(" ")[3]))
        break
    

    Let me know if it does not work for you !!

提交回复
热议问题