diff options
author | Guido van Rossum <guido@python.org> | 2000-08-22 02:04:46 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 2000-08-22 02:04:46 (GMT) |
commit | 2823f03a56451f3187a1d85ffcef107f00f6f48e (patch) | |
tree | f28495af8324ca3337e07fc30617dfa7b3318504 /Lib | |
parent | 986659fffed674ca28786231137134941b40ff27 (diff) | |
download | cpython-2823f03a56451f3187a1d85ffcef107f00f6f48e.zip cpython-2823f03a56451f3187a1d85ffcef107f00f6f48e.tar.gz cpython-2823f03a56451f3187a1d85ffcef107f00f6f48e.tar.bz2 |
Patch by Toby Dickenson: don't die when an error occurs during string
conversion in an exception, but instead display <unprintable %s
object> where %s is the type name.
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/traceback.py | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/Lib/traceback.py b/Lib/traceback.py index d219340..b733598 100644 --- a/Lib/traceback.py +++ b/Lib/traceback.py @@ -166,9 +166,15 @@ def format_exception_only(etype, value): s = s + ' ' list.append('%s^\n' % s) value = msg - list.append('%s: %s\n' % (str(stype), str(value))) + list.append('%s: %s\n' % (str(stype), _some_str(value))) return list +def _some_str(value): + try: + return str(value) + except: + return '<unprintable %s object>' % type(value).__name__ + def print_exc(limit=None, file=None): """This is a shorthand for 'print_exception(sys.exc_type, |