How to log error to file, and not fail on exception

后端 未结 4 2019
忘了有多久
忘了有多久 2021-01-31 16:55

I am downloading a file from the net, and it fails even though I am doing:

for p in query:

try:

except IOError as e:
   print e;

If th

4条回答
  •  误落风尘
    2021-01-31 17:43

    This catches everything. But it is much, much better to catch the exact exception. python <= 2.7

    while True:
      try:
        doStuff()
      except Exception, e:
        f = open('log.txt', 'w')
        f.write('An exceptional thing happed - %s' % e)
        f.close()
    

提交回复
热议问题