Merge "Fix HierarchyViewer so it can load Contacts" into jb-mr1-dev
diff --git a/core/java/android/view/ViewDebug.java b/core/java/android/view/ViewDebug.java
index 1286eb9..c013d85 100644
--- a/core/java/android/view/ViewDebug.java
+++ b/core/java/android/view/ViewDebug.java
@@ -1178,10 +1178,14 @@
 
     private static void writeValue(BufferedWriter out, Object value) throws IOException {
         if (value != null) {
-            String output = value.toString().replace("\n", "\\n");
-            out.write(String.valueOf(output.length()));
-            out.write(",");
-            out.write(output);
+            String output = "[EXCEPTION]";
+            try {
+                output = value.toString().replace("\n", "\\n");
+            } finally {
+                out.write(String.valueOf(output.length()));
+                out.write(",");
+                out.write(output);
+            }
         } else {
             out.write("4,null");
         }