How to get exception message in Python properly

前端 未结 4 1905
青春惊慌失措
青春惊慌失措 2020-11-27 13:25

What is the best way to get exceptions\' messages from components of standard library in Python?

I noticed that in some cases you can get it via message

4条回答
  •  暗喜
    暗喜 (楼主)
    2020-11-27 13:56

    I had the same problem. I think the best solution is to use log.exception, which will automatically print out stack trace and error message, such as:

    try:
        pass
        log.info('Success')
    except:
        log.exception('Failed')
    

提交回复
热议问题