List of usage examples for java.lang StackTraceElement toString
public String toString()
From source file:net.fenyo.gnetwatch.GenericTools.java
/** * Returns the full stack trace./*from w ww. j a va 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:org.nuxeo.ecm.webengine.servlet.WebServlet.java
protected static void displayError(HttpServletResponse resp, Throwable t, String message, int code) { PrintWriter writer;/* www .j av a 2s . c o m*/ try { writer = resp.getWriter(); } catch (IOException e) { log.error("Unable to output Error ", e); log.error("Application error was " + message, e); return; } writer.write("\nError occured during Site rendering"); writer.write("\nSite Error message : " + message); if (t != null) { writer.write("\nException message : " + t.getMessage()); for (StackTraceElement element : t.getStackTrace()) { writer.write("\n" + element.toString()); } } resp.setStatus(code); }
From source file:org.apache.hama.util.ReflectionUtils.java
/** * Print all of the thread's information and stack traces. * //w w w . j a va 2 s. co m * @param stream the stream to * @param title a string title for the stack trace */ public synchronized static void printThreadInfo(PrintWriter stream, String title) { final int STACK_DEPTH = 20; boolean contention = threadBean.isThreadContentionMonitoringEnabled(); long[] threadIds = threadBean.getAllThreadIds(); stream.println("Process Thread Dump: " + title); stream.println(threadIds.length + " active threads"); for (long tid : threadIds) { ThreadInfo info = threadBean.getThreadInfo(tid, STACK_DEPTH); if (info == null) { stream.println(" Inactive"); continue; } stream.println("Thread " + getTaskName(info.getThreadId(), info.getThreadName()) + ":"); Thread.State state = info.getThreadState(); stream.println(" State: " + state); stream.println(" Blocked count: " + info.getBlockedCount()); stream.println(" Waited count: " + info.getWaitedCount()); if (contention) { stream.println(" Blocked time: " + info.getBlockedTime()); stream.println(" Waited time: " + info.getWaitedTime()); } if (state == Thread.State.WAITING) { stream.println(" Waiting on " + info.getLockName()); } else if (state == Thread.State.BLOCKED) { stream.println(" Blocked on " + info.getLockName()); stream.println(" Blocked by " + getTaskName(info.getLockOwnerId(), info.getLockOwnerName())); } stream.println(" Stack:"); for (StackTraceElement frame : info.getStackTrace()) { stream.println(" " + frame.toString()); } } stream.flush(); }
From source file:Main.java
public static String getCallLocation(String fqn) { if (!java13) { try {//from ww w. j a va 2s .c o m StackTraceElement[] ste = new Throwable().getStackTrace(); for (int i = 0; i < ste.length - 1; i++) { if (fqn.equals(ste[i].getClassName())) { StackTraceElement callLocation = ste[i + 1]; String nextClassName = callLocation.getClassName(); if (nextClassName.equals(fqn)) { continue; } return callLocation.toString(); } } } catch (Throwable e) { java13 = true; } } return null; }
From source file:Main.java
static public String toString(ThreadInfo threadInfo) { StringBuilder sb = new StringBuilder("\"" + threadInfo.getThreadName() + "\"" + " Id=" + threadInfo.getThreadId() + " " + threadInfo.getThreadState()); if (threadInfo.getLockName() != null) { sb.append(" on " + threadInfo.getLockName()); }// w ww. j a v a2 s . co m if (threadInfo.getLockOwnerName() != null) { sb.append(" owned by \"" + threadInfo.getLockOwnerName() + "\" Id=" + threadInfo.getLockOwnerId()); } if (threadInfo.isSuspended()) { sb.append(" (suspended)"); } if (threadInfo.isInNative()) { sb.append(" (in native)"); } sb.append('\n'); int i = 0; StackTraceElement[] stackTrace = threadInfo.getStackTrace(); for (StackTraceElement ste : stackTrace) { // for (; i < threadInfo.getStackTrace().length && i < 64; i++) { // StackTraceElement ste = stackTrace[i]; sb.append("\tat " + ste.toString()); sb.append('\n'); if (i == 0 && threadInfo.getLockInfo() != null) { Thread.State ts = threadInfo.getThreadState(); switch (ts) { case BLOCKED: sb.append("\t- blocked on " + threadInfo.getLockInfo()); sb.append('\n'); break; case WAITING: sb.append("\t- waiting on " + threadInfo.getLockInfo()); sb.append('\n'); break; case TIMED_WAITING: sb.append("\t- waiting on " + threadInfo.getLockInfo()); sb.append('\n'); break; default: } } for (MonitorInfo mi : threadInfo.getLockedMonitors()) { if (mi.getLockedStackDepth() == i) { sb.append("\t- locked " + mi); sb.append('\n'); } } } if (i < stackTrace.length) { sb.append("\t..."); sb.append('\n'); } LockInfo[] locks = threadInfo.getLockedSynchronizers(); if (locks.length > 0) { sb.append("\n\tNumber of locked synchronizers = " + locks.length); sb.append('\n'); for (LockInfo li : locks) { sb.append("\t- " + li); sb.append('\n'); } } sb.append('\n'); return sb.toString(); }
From source file:com.qualogy.qafe.business.integration.java.JavaServiceProcessor.java
private static String resolveErrorMessage(Throwable cause) { String errorMessage = null;/*from w ww . j a v a 2s . c o m*/ if (cause instanceof NullPointerException) { StackTraceElement[] stackTraceElements = ((NullPointerException) cause).getStackTrace(); StackTraceElement stackTraceElement = stackTraceElements[0]; errorMessage = cause.toString() + ": " + stackTraceElement.toString(); } else { errorMessage = cause.getMessage(); } if (errorMessage != null) { errorMessage = errorMessage.trim(); } return errorMessage; }
From source file:com.jaeksoft.searchlib.Logging.java
public final static void warn(String msg, StackTraceElement[] stackTrace) { logger.warn(msg);/*w w w. j a va2 s . c o m*/ for (StackTraceElement element : stackTrace) if (element.getClassName().startsWith("com.jaeksoft")) logger.warn(element.toString()); }
From source file:org.tranche.add.AddFileToolUtil.java
/** * /*from w ww . j a va2s . c om*/ * @param recipients * @param aft * @param report */ public static void emailFailureNotice(String[] recipients, AddFileTool aft, AddFileToolReport report) { String subject = "[" + ConfigureTranche.get(ConfigureTranche.CATEGORY_GENERAL, ConfigureTranche.PROP_NAME) + "] Failed Upload @ " + TextUtil.getFormattedDate(TimeUtil.getTrancheTimestamp()); final StringBuffer message = new StringBuffer(); try { message.append("An upload failed at " + TextUtil.getFormattedDate(TimeUtil.getTrancheTimestamp()) + " due to:" + "\n" + "\n"); for (PropagationExceptionWrapper e : report.getFailureExceptions()) { message.append("* " + e.exception.getClass().getName() + ": " + e.exception.getMessage() + "\n"); for (StackTraceElement ste : e.exception.getStackTrace()) { message.append(" - " + ste.toString() + "\n"); } message.append("\n"); } message.append("Title: " + aft.getTitle() + "\n" + "\n"); message.append("Description: " + aft.getDescription() + "\n" + "\n"); message.append(LogUtil.getTroubleshootingInformation() + "\n" + "\n"); // Build up string list of admin email addresses to which user can forward error StringBuffer adminEmailListBuffer = new StringBuffer(); final String[] a = ConfigureTranche.getAdminEmailAccounts(); for (int i = 0; i < a.length; i++) { adminEmailListBuffer.append(a[i]); if (i < a.length - 1) { adminEmailListBuffer.append(", "); } } } catch (Exception e) { e.printStackTrace(); } EmailUtil.safeSendEmail(subject, recipients, message.toString()); }
From source file:org.midonet.midolman.Midolman.java
public static void dumpStacks() { Map<Thread, StackTraceElement[]> traces = Thread.getAllStackTraces(); for (Thread thread : traces.keySet()) { System.err.print("\"" + thread.getName() + "\" "); if (thread.isDaemon()) System.err.print("daemon "); System.err.print(String.format("prio=%x tid=%x %s [%x]\n", thread.getPriority(), thread.getId(), thread.getState(), System.identityHashCode(thread))); StackTraceElement[] trace = traces.get(thread); for (StackTraceElement e : trace) { System.err.println(" at " + e.toString()); }// w ww . j a v a 2s . com } }
From source file:org.gradle.util.DeprecationLogger.java
private static void logTraceIfNecessary() { if (isTraceLoggingEnabled()) { StackTraceElement[] stack = StackTraceUtils.sanitize(new Exception()).getStackTrace(); for (StackTraceElement frame : stack) { if (!frame.getClassName().startsWith(DeprecationLogger.class.getName())) { LOGGER.warn(" {}", frame.toString()); }/*from w ww. j a va 2 s . co m*/ } } }