Python: Getting the error message of an exception

后端 未结 4 1474
孤独总比滥情好
孤独总比滥情好 2021-01-03 17:40

In python 2.6.6, how can I capture the error message of an exception.

IE:

response_dict = {} # contains info to response under a django view.
try:
           


        
4条回答
  •  执笔经年
    2021-01-03 18:26

    Everything about str is correct, yet another answer: an Exception instance has message attribute, and you may want to use it (if your customized IntegrityError doesn't do something special):

    except IntegrityError, e: #contains my own custom exception raising with custom messages.
        response_dict.update({'error': e.message})
    

提交回复
热议问题