Posted By

freephys on 12/18/09


Tagged

exception traceback


Versions (?)

8.4. Trapping and Recording Exceptions


 / Published in: Python
 

  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  

You need to login to post a comment.