1 5 package org.exoplatform.commons.utils; 6 7 13 public class ExceptionUtil { 14 private static String LINE_SEPARATOR = System.getProperty("line.separator") ; 15 16 static public String getExoStackTrace(Throwable t) { 17 StackTraceElement [] elements = t.getStackTrace() ; 18 StringBuffer b = new StringBuffer () ; 19 b.append(t.getMessage()).append(LINE_SEPARATOR) ; 20 boolean appendDot = true ; 21 for(int i = 0; i < elements.length ; i++) { 22 if(i < 10) { 23 b.append(" at ").append(elements[i].toString()).append(LINE_SEPARATOR) ; 24 } else { 25 if(elements[i].getClassName().startsWith("exo.")) { 26 b.append(" at ").append(elements[i].toString()).append(LINE_SEPARATOR) ; 27 appendDot = true ; 28 } else { 29 if(appendDot) { 30 b.append(" [...................................]").append(LINE_SEPARATOR) ; 31 appendDot = false ; 32 } 33 } 34 } 35 } 36 return b.toString() ; 37 } 38 39 static public String getStackTrace(Throwable t, int numberOfLine) { 40 StackTraceElement [] elements = t.getStackTrace() ; 41 if(numberOfLine > elements.length) numberOfLine = elements.length ; 42 StringBuffer b = new StringBuffer () ; 43 b.append(t.getMessage()).append(LINE_SEPARATOR) ; 44 for(int i = 0; i < numberOfLine; i++) { 45 b.append(elements[i].toString()).append(LINE_SEPARATOR) ; 46 } 47 return b.toString() ; 48 } 49 50 static public Throwable getRootCause(Throwable t) { 51 Throwable root = t ; 52 while(root.getCause() != null) { 53 root = root.getCause() ; 54 } 55 return root ; 56 } 57 } 58 | Popular Tags |