]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Patch by Toby Dickenson: don't die when an error occurs during string
authorGuido van Rossum <guido@python.org>
Tue, 22 Aug 2000 02:04:46 +0000 (02:04 +0000)
committerGuido van Rossum <guido@python.org>
Tue, 22 Aug 2000 02:04:46 +0000 (02:04 +0000)
conversion in an exception, but instead display <unprintable %s
object> where %s is the type name.

Lib/traceback.py

index d219340a80be485d3ac9d73d184c08769cbcbb48..b733598f258476b34721d8b99a133e7d28a65eb0 100644 (file)
@@ -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,