def printable_exception(exc): tn = typename(exc) msg = str(exc) return f"{tn}: {msg}" if msg else tn def typename(obj): return type(obj).__name__