def format_exc(limit=None):
 try:
  (etype, value, tb) = sys.exc_info()
  return ''.join(traceback.format_exception(etype, value, tb, limit))
 finally:
  etype = value = tb = None

def format_exc ( limit = None ) : try : ( etype , value , tb ) = sys . exc_info ( ) return '' . join ( traceback . format_exception ( etype , value , tb , limit ) ) finally : etype = value = tb = None
like print_exc() but return a string .