A bare except Exception as e: print(e) throws away the most useful part of an error: where it happened. traceback.print_exc() keeps it.
import traceback
for path in files:
try:
process(path)
except Exception:
print(f"failed on {path}")
traceback.print_exc()
Inside an except block it prints the same traceback you’d see if the exception had crashed the program, with every file, line number and the line of code, and then the loop just continues with the next file. On recent Python versions you even get the little markers under the exact expression that failed.
print(e) on its own often gives you something like 'name' for a KeyError, which tells you nothing. The traceback tells you which dict, in which function, called from where.
It writes to stderr by default. Pass file=sys.stdout or an open file if you want it elsewhere, or use traceback.format_exc() to get it as a string you can put in a status message or an email.
The trap is catching too much. A broad except Exception that prints and moves on is right for a batch job where one bad file shouldn’t stop the rest. In code where a failure means the result is wrong, I’d rather let it crash. And if the program already uses logging, log.exception() is the better fit, because the traceback then goes wherever your logs go.
Further reading: traceback.print_exc