python exception message capturing

前端 未结 11 1699
醉梦人生
醉梦人生 2020-12-12 09:06
import ftplib
import urllib2
import os
import logging
logger = logging.getLogger(\'ftpuploader\')
hdlr = logging.FileHandler(\'ftplog.log\')
formatter = logging.Form         


        
11条回答
  •  醉酒成梦
    2020-12-12 09:30

    You can try specifying the BaseException type explicitly. However, this will only catch derivatives of BaseException. While this includes all implementation-provided exceptions, it is also possibly to raise arbitrary old-style classes.

    try:
      do_something()
    except BaseException, e:
      logger.error('Failed to do something: ' + str(e))
    

提交回复
热议问题