List of usage examples for java.lang Throwable getStackTrace
public StackTraceElement[] getStackTrace()
From source file:com.cisco.dbds.utils.logging.LogHandler.java
/** * In Stack trace the first element will be the current object invoked(which * is always the logger object) The first element will be the caller object. * * @return the current method info/*from ww w. ja va 2s . c o m*/ */ private static String getCurrentMethodInfo() { Throwable t = new Throwable(); StackTraceElement[] elements = t.getStackTrace(); // String calleeMethod = elements[0].getMethodName(); String callerMethodName = elements[3].getMethodName(); String[] classNames = elements[3].getClassName().split("\\."); String callerClassName = classNames[classNames.length - 1]; return callerClassName + ": " + callerMethodName + "(): "; }
From source file:io.cloudslang.content.json.utils.JsonUtils.java
@NotNull public static IllegalArgumentException hammerIllegalArgumentExceptionWithMessage(@NotNull final String message, @NotNull final Throwable throwable) { final IllegalArgumentException iae = new IllegalArgumentException(message); iae.setStackTrace(throwable.getStackTrace()); return iae;/*w w w.j a v a2s .c o m*/ }
From source file:org.apache.drill.exec.store.mapr.db.json.OjaiFunctionsProcessor.java
private static String getStackTrace() { final Throwable throwable = new Throwable(); final StackTraceElement[] ste = throwable.getStackTrace(); final StringBuilder sb = new StringBuilder(); for (int i = 1; i < ste.length; ++i) { sb.append(ste[i].toString());//from w w w . ja v a2s .co m sb.append('\n'); } return sb.toString(); }
From source file:Main.java
public static String getStackTrace(Throwable t) { String CRLF = System.getProperty("line.separator"); StringBuffer sb = new StringBuffer(); sb.append(t.toString() + CRLF);//from www. ja va 2 s . com StackTraceElement[] se = t.getStackTrace(); if (se != null) { for (int i = 0; i < se.length; i++) { if (se[i] != null) { sb.append("\t" + se[i].toString()); if (i != se.length - 1) { sb.append(CRLF); } } } } return sb.toString(); }
From source file:questionnaire.Result.java
public static <T> Result<T> fail(Throwable t) { StringBuilder sb = new StringBuilder(); sb.append(t.getClass());//from w w w. ja v a2s.com sb.append(": \""); sb.append(t.getMessage()); sb.append("\"<br />\n"); for (StackTraceElement ste : t.getStackTrace()) { sb.append(ste); sb.append("<br />\n"); } return fail(sb.toString()); }
From source file:org.jgentleframework.utils.ExceptionUtils.java
/** * Fill the current client-side stack trace into the given exception. * <p>//w w w . j a v a 2 s.c o m * The given exception is typically thrown on the server and serialized * as-is, with the client wanting it to contain the client-side portion of * the stack trace as well. What we can do here is to update the * <code>StackTraceElement</code> array with the current client-side stack * trace, provided that we run on JDK 1.5+. * * @param ex * the exception to update * @see java.lang.Throwable#getStackTrace() * @see java.lang.Throwable#setStackTrace(StackTraceElement[]) */ public static void fillInClientStackTraceIfPossible(Throwable ex) { if (ex != null) { StackTraceElement[] clientStack = new Throwable().getStackTrace(); Set<Throwable> visitedExceptions = new HashSet<Throwable>(); Throwable exToUpdate = ex; while (exToUpdate != null && !visitedExceptions.contains(exToUpdate)) { StackTraceElement[] serverStack = exToUpdate.getStackTrace(); StackTraceElement[] combinedStack = new StackTraceElement[serverStack.length + clientStack.length]; System.arraycopy(serverStack, 0, combinedStack, 0, serverStack.length); System.arraycopy(clientStack, 0, combinedStack, serverStack.length, clientStack.length); exToUpdate.setStackTrace(combinedStack); visitedExceptions.add(exToUpdate); exToUpdate = exToUpdate.getCause(); } } }
From source file:io.stallion.services.Log.java
public static void finest(String message, Object... args) { if (getLogLevel().intValue() > Level.FINEST.intValue()) { return;/*from w w w .java 2 s .c o m*/ } //System.out.println(message); Throwable t = new Throwable(); t.getStackTrace()[2].toString(); String clz = t.getStackTrace()[2].getClassName().replace("io.stallion.", ""); String method = t.getStackTrace()[2].getMethodName(); logger.logp(Level.FINEST, clz, method, message, args); }
From source file:io.stallion.services.Log.java
public static void finer(String message, Object... args) { if (getLogLevel().intValue() > Level.FINER.intValue()) { return;/*from www . j av a2s . c om*/ } //System.out.println(message); Throwable t = new Throwable(); t.getStackTrace()[2].toString(); String clz = t.getStackTrace()[2].getClassName().replace("io.stallion.", ""); String method = t.getStackTrace()[2].getMethodName(); logger.logp(Level.FINER, clz, method, message, args); }
From source file:net.fenyo.gnetwatch.GenericTools.java
/** * Returns the full stack trace.//from w w w . j av a 2 s . c om * This function is a replacement to Throwable.getStackTrace() that writes "... XX [lines] more" * when there are too many entries in the stack trace. * @param ex exception. * @return String exception description with full stack trace. */ static public String getFullExceptionStackTrace(final Throwable ex) { String result = ""; for (final StackTraceElement st : ex.getStackTrace()) result += st.toString(); if (ex.getCause() != null) { result += "caused by\n"; for (final StackTraceElement st : ex.getCause().getStackTrace()) result += st.toString(); } return result; }
From source file:io.stallion.services.Log.java
public static void fine(String message, Object... args) { if (getLogLevel().intValue() > Level.FINE.intValue()) { return;/*from w ww . j ava 2 s .co m*/ } //System.out.println(message); if (alwaysIncludeLineNumber) { Throwable t = new Throwable(); t.getStackTrace()[2].toString(); String clz = t.getStackTrace()[2].getClassName().replace("io.stallion.", ""); String method = t.getStackTrace()[2].getMethodName(); logger.logp(Level.FINE, clz, method, message, args); } else { logger.logp(Level.FINE, "", "", message, args); } }