refactor traceback.py to reduce code duplication (closes #17646)

Patch by Martin Morrison.
2 files changed