geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From delaf...@apache.org
Subject svn commit: r159304 - geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/util/ExceptionUtil.java
Date Mon, 28 Mar 2005 20:38:34 GMT
Author: delafran
Date: Mon Mar 28 12:38:33 2005
New Revision: 159304

URL: http://svn.apache.org/viewcvs?view=rev&rev=159304
Log:
Added help method for causedBy

Modified:
    geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/util/ExceptionUtil.java

Modified: geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/util/ExceptionUtil.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/util/ExceptionUtil.java?view=diff&r1=159303&r2=159304
==============================================================================
--- geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/util/ExceptionUtil.java
(original)
+++ geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/util/ExceptionUtil.java
Mon Mar 28 12:38:33 2005
@@ -74,6 +74,35 @@
         return "\nCaused by: " + getStackTrace(ex) + getDivider();
     }
 
+    public static String causedBy(String stackTrace)
+    {
+        return "\nCaused by: " + getTraceLines(stackTrace);
+    }
+
+    public static Throwable getCause(Throwable ex)
+    {
+        for (;;)
+        {
+            if (ex instanceof SystemException)
+            {
+                SystemException se = (SystemException)ex;
+                if (se.getCause() != null && se.getMessage() == null)
+                {
+                    ex = se.getCause();
+                }
+                else
+                {
+                    break;
+                }
+            }
+            else
+            {
+                break;
+            }
+        }
+        return ex;
+    }
+
     public static String getCauseChain(Throwable ex) {
         String stackTrace = getStackTrace(ex);
         return getCauseChain(stackTrace);
@@ -103,6 +132,37 @@
         java.io.PrintWriter pw = new java.io.PrintWriter(sw);
         ex.printStackTrace(pw);
         return sw.toString().trim();
+    }
+
+    public static String getTraceLines(String stackTrace)
+    {
+        try
+        {
+            BufferedReader input = new BufferedReader(new StringReader(stackTrace));
+            StringBuffer output = new StringBuffer(100);
+            String line;
+            boolean first = true;
+            while ((line = input.readLine()) != null)
+            {
+                line = line.trim();
+                if (line.length() != 0)
+                {
+                    if (! first)
+                    {
+                        output.append("| ");
+                    }
+                    first = false;
+                    output.append(line);
+                    output.append('\n');
+                }
+            }
+            return output.toString();
+        }
+        catch (Exception ex2)
+        {
+            ex2.printStackTrace();
+            return stackTrace;
+        }
     }
 
     public static String getCurrentStackTrace() {



Mime
View raw message