Refactor monitor and exceptions
[lgpl/argeo-commons.git] / org.argeo.util / src / org / argeo / util / LangUtils.java
index 3c0baed1c8047ad0c9cccb10a77c12a84def8912..8810d646335056a604791cec8a545b27931be1b9 100644 (file)
@@ -136,6 +136,27 @@ public class LangUtils {
                        res.put(key.toString(), toLoad.get(key));
                return res;
        }
+       
+       /*
+        * EXCEPTIONS
+        */
+       /**
+        * Chain the messages of all causes (one per line, <b>starts with a line
+        * return</b>) without all the stack
+        */
+       public static String chainCausesMessages(Throwable t) {
+               StringBuffer buf = new StringBuffer();
+               chainCauseMessage(buf, t);
+               return buf.toString();
+       }
+
+       /** Recursive chaining of messages */
+       private static void chainCauseMessage(StringBuffer buf, Throwable t) {
+               buf.append('\n').append(' ').append(t.getClass().getCanonicalName())
+                               .append(": ").append(t.getMessage());
+               if (t.getCause() != null)
+                       chainCauseMessage(buf, t.getCause());
+       }
 
        /** Singleton constructor. */
        private LangUtils() {