Guard thread exited message by try-catch in ThreadStress

Bug: 18577101
Change-Id: I1c3cbbfad09b88f4d913dc86bb6a89bf5b5269a8
diff --git a/test/004-ThreadStress/src/Main.java b/test/004-ThreadStress/src/Main.java
index 7acd950..d5b389f 100644
--- a/test/004-ThreadStress/src/Main.java
+++ b/test/004-ThreadStress/src/Main.java
@@ -448,9 +448,14 @@
                             thread.join();
                         } catch (InterruptedException e) {
                         }
-                        System.out.println("Thread exited for " + id + " with "
-                                           + (operationsPerThread - threadStress.nextOperation)
-                                           + " operations remaining.");
+                        try {
+                            System.out.println("Thread exited for " + id + " with "
+                                               + (operationsPerThread - threadStress.nextOperation)
+                                               + " operations remaining.");
+                        } catch (OutOfMemoryError e) {
+                            // Ignore OOME since we need to print "Finishing worker" for the test
+                            // to pass.
+                        }
                     }
                     System.out.println("Finishing worker");
                 }