8.4. Trapping and Recording Exceptions


/ Published in: Python
Save to your folder(s)



Copy this code and paste it in your HTML
  1. import cStringIO, traceback
  2. def process_all_files(all_filenames,
  3. fatal_exceptions=(KeyboardInterrupt, MemoryError)
  4. ):
  5. bad_filenames = { }
  6. for one_filename in all_filenames:
  7. try:
  8. process_one_file(one_filename):
  9. except fatal_exceptions:
  10. raise
  11. except Exception:
  12. f = cStringIO.StringIO( )
  13. traceback.print_exc(file=f)
  14. bad_filenames[one_filename] = f.getvalue( )
  15. return bad_filenames

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.