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.
This commit is contained in:
Guido van Rossum 2000-08-22 02:04:46 +00:00
parent 986659fffe
commit 2823f03a56
1 changed files with 7 additions and 1 deletions

View File

@ -166,9 +166,15 @@ def format_exception_only(etype, value):
s = s + ' ' s = s + ' '
list.append('%s^\n' % s) list.append('%s^\n' % s)
value = msg value = msg
list.append('%s: %s\n' % (str(stype), str(value))) list.append('%s: %s\n' % (str(stype), _some_str(value)))
return list 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): def print_exc(limit=None, file=None):
"""This is a shorthand for 'print_exception(sys.exc_type, """This is a shorthand for 'print_exception(sys.exc_type,