#1065986: add missing error handler in pydoc unicode fix.
diff --git a/Lib/pydoc.py b/Lib/pydoc.py
index e8b6c08..160ad4a 100755
--- a/Lib/pydoc.py
+++ b/Lib/pydoc.py
@@ -209,7 +209,9 @@
 def _binstr(obj):
     # Ensure that we have an encoded (binary) string representation of obj,
     # even if it is a unicode string.
-    return obj.encode(_encoding) if isinstance(obj, _unicode) else str(obj)
+    if isinstance(obj, _unicode):
+        return obj.encode(_encoding, 'xmlcharrefreplace')
+    return str(obj)
 
 # ----------------------------------------------------- module manipulation