Example usage for java.lang StackTraceElement toString

List of usage examples for java.lang StackTraceElement toString

Introduction

In this page you can find the example usage for java.lang StackTraceElement toString.

Prototype

public String toString() 

Source Link

Document

Returns a string representation of this stack trace element.

Usage

From source file:org.rhq.core.pc.inventory.AvailabilityExecutor.java

static private String getSmallStackTrace(Throwable t) {
    StringBuilder smallStack = new StringBuilder();

    StackTraceElement[] stack = (null == t) ? new Exception().getStackTrace() : t.getStackTrace();
    for (int i = 1; i < stack.length; i++) {
        StackTraceElement ste = stack[i];
        if (ste.getClassName().startsWith("org.rhq")) {
            smallStack.append(ste.toString());
            smallStack.append("\n");
        }/* w  ww  . j a va  2  s.  c o m*/
    }
    return smallStack.toString();
}

From source file:org.projectforge.common.ExceptionHelper.java

/**
 * Gets the stackTrace of the given message in the form "at
 * org.projectforge.access.AccessChecker.hasPermission(AccessChecker.java:79) at
 * org.projectforge.task.TaskDao.hasInsertAccess(TaskDao.java:176) at ..." without entries does not match the beginning of
 * only4Namespace. <br/> Also stack trace entries containing "CGLIB$$" will be ignored in the output.
 * @param ex/*from ww  w. j  av a2s . c om*/
 * @param only4Namespace
 * @return
 */
public static String getFilteredStackTrace(Throwable ex, String only4Namespace) {
    StringBuffer buf = new StringBuffer();
    StackTraceElement[] sta = ex.getStackTrace();
    boolean ignored = false;
    if (sta != null && sta.length > 0) {
        for (StackTraceElement ste : sta) {
            if (ignored == true) {
                if (ignore(ste.getClassName(), only4Namespace) == true) {
                    continue;
                }
            } else {
                ignored = false;
            }
            if (ignore(ste.getClassName(), only4Namespace) == true) {
                buf.append(" at ...");
                ignored = true;
                continue;
            }
            buf.append(" at ");
            buf.append(ste.toString());
        }
    }
    return buf.toString();
}

From source file:org.red5.server.net.remoting.FlexMessagingService.java

/**
 * Construct error message from exception.
 * /*from ww  w.  j  a  v a2 s  . c o  m*/
 * @param request request
 * @param faultCode fault code
 * @param faultString fautl string
 * @param error error
 * @return message
 */
public static ErrorMessage returnError(AbstractMessage request, String faultCode, String faultString,
        Throwable error) {
    ErrorMessage result = returnError(request, faultCode, faultString, "");
    if (error instanceof ClientDetailsException) {
        result.extendedData = ((ClientDetailsException) error).getParameters();
        if (((ClientDetailsException) error).includeStacktrace()) {
            StringBuilder stack = new StringBuilder();
            for (StackTraceElement element : error.getStackTrace()) {
                stack.append(element.toString()).append('\n');
            }
            result.faultDetail = stack.toString();
        }
    }
    result.rootCause = error;
    return result;
}

From source file:com.gtwm.pb.servlets.ServletUtilMethods.java

/**
 * Return a string for logging purposes, of an exception's 'cause stack',
 * i.e. the original exception(s) thrown and stack trace, i.e. the methods
 * that the exception was thrown through.
 * //from   w w w.  j a  va2  s . co  m
 * Called by logException
 */
private static String getExceptionCauses(Exception ex) {
    String errorMessage = ex.toString() + "\r\n";
    if (ex.getCause() != null) {
        // Recursively find causes of exception
        errorMessage += " - Error was due to...";
        Exception exceptionCause = ex;
        String causeIndent = " - ";
        errorMessage += causeIndent + ex.toString() + "\r\n";
        while (exceptionCause.getCause() != null) {
            if (exceptionCause.getCause() instanceof Exception) {
                exceptionCause = (Exception) exceptionCause.getCause();
                causeIndent += " - ";
                errorMessage += causeIndent + getExceptionCauses(exceptionCause);
            }
        }
    }
    // Include out relevant parts of the stack trace
    StackTraceElement[] stackTrace = ex.getStackTrace();
    if (stackTrace.length > 0) {
        errorMessage += " - Stack trace:\r\n";
        int nonGtwmClassesLogged = 0;
        for (StackTraceElement stackTraceElement : stackTrace) {
            if (!stackTraceElement.getClassName().startsWith("com.gtwm.")) {
                nonGtwmClassesLogged++;
            }
            // Only trace our own classes + a few more, stop shortly after
            // we get to java language or 3rd party classes
            if (nonGtwmClassesLogged < 15) {
                errorMessage += "   " + stackTraceElement.toString() + "\r\n";
            }
        }
    }
    return errorMessage;
}

From source file:gov.nih.nci.nbia.StandaloneDMDispatcher.java

static void printStackTraceToDialog(String note, Exception e) {
    StringBuilder sb = new StringBuilder(note);
    sb.append(e.getMessage());//  w  w w. j  av  a  2 s  . c  o  m
    sb.append("\n");
    for (StackTraceElement ste : e.getStackTrace()) {
        sb.append(ste.toString());
        sb.append("\n");
    }
    JTextArea jta = new JTextArea(sb.toString());
    JScrollPane jsp = new JScrollPane(jta) {
        @Override
        public Dimension getPreferredSize() {
            return new Dimension(480, 320);
        }
    };
    JOptionPane.showMessageDialog(null, jsp, "Error", JOptionPane.ERROR_MESSAGE);
}

From source file:pcgen.util.Logging.java

/**
 * List the current stack of all threads to STDOUT. 
 *///from   ww  w .j a  v  a  2s . c  o m
public static void reportAllThreads() {
    Map<Thread, StackTraceElement[]> allThreads = Thread.getAllStackTraces();
    StringBuilder b = new StringBuilder();
    for (Thread t : allThreads.keySet()) {
        b.append("Thread: ");
        b.append(t.getName());
        b.append(", stacktrace:\n");
        StackTraceElement[] traces = allThreads.get(t);
        for (StackTraceElement element : traces) {
            b.append("  ");
            b.append(element.toString());
            b.append('\n');
        }

    }
    System.out.println("==== Thread listing ====");
    System.out.println(b);
    System.out.println("===== end listing  =====");
}

From source file:biz.bokhorst.xprivacy.Util.java

public static void logStack(XHook hook, int priority, boolean cl) {
    StringBuilder trace = new StringBuilder();
    ClassLoader loader = Thread.currentThread().getContextClassLoader();
    for (StackTraceElement ste : Thread.currentThread().getStackTrace()) {
        trace.append(ste.toString());
        if (cl)/*w w  w.  ja v  a  2  s .c o m*/
            try {
                Class<?> clazz = Class.forName(ste.getClassName(), false, loader);
                trace.append(" [");
                trace.append(clazz.getClassLoader().toString());
                trace.append("]");
            } catch (ClassNotFoundException ignored) {
            }
        trace.append("\n");
    }
    log(hook, priority, trace.toString());
}

From source file:com.evolveum.midpoint.util.logging.LoggingUtils.java

public static String dumpStackTrace(Class... classesToSkip) {
    StackTraceElement[] fullStack = Thread.currentThread().getStackTrace();
    String immediateClass = null;
    String immediateMethod = null;
    boolean firstFrameLogged = false;
    StringBuilder sb = new StringBuilder();
    OUTER: for (StackTraceElement stackElement : fullStack) {
        if (!firstFrameLogged) {
            if (stackElement.getClassName().equals(Thread.class.getName())) {
                // skip call to thread.getStackTrace();
                continue;
            }/*from  ww w  . j  a v  a 2s .com*/
            if (classesToSkip != null) {
                for (Class classToSkip : classesToSkip) {
                    if (stackElement.getClassName().equals(classToSkip.getName())) {
                        continue OUTER;
                    }
                }
            }
        }
        firstFrameLogged = true;

        sb.append(stackElement.toString());
        sb.append("\n");
    }
    return sb.toString();
}

From source file:org.tap4j.ext.testng.TestNGYAMLishUtils.java

/**
 * @param testNgTestResult//from   w w w  . j  a  va  2s .  com
 * @return Line value
 */
public static String getLine(ITestResult testNgTestResult) {
    String line = "~";
    Throwable testNGException = testNgTestResult.getThrowable();
    if (testNGException != null) {
        StringBuilder lookFor = new StringBuilder();
        lookFor.append(testNgTestResult.getTestClass().getName());
        lookFor.append('.');
        lookFor.append(testNgTestResult.getMethod().getMethodName());
        lookFor.append('(');
        lookFor.append(testNgTestResult.getTestClass().getClass().getSimpleName());
        lookFor.append(".java:");

        StackTraceElement[] els = testNGException.getStackTrace();

        for (int i = 0; i < els.length; i++) {
            StackTraceElement el = els[i];
            line = getLineNumberFromExceptionTraceLine(el.toString(), lookFor.toString());
            if (line != "") {
                break;
            }
        }
    }
    return line;
}

From source file:uk.co.armedpineapple.cth.SDLActivity.java

public static void flipEGL() {
    try {//from  w  w  w .  java 2  s  .  c  o m
        EGL10 egl = (EGL10) EGLContext.getEGL();

        egl.eglWaitNative(EGL10.EGL_CORE_NATIVE_ENGINE, null);

        // drawing here

        egl.eglWaitGL();

        egl.eglSwapBuffers(SDLActivity.mEGLDisplay, SDLActivity.mEGLSurface);

    } catch (Exception e) {
        Log.v("SDL", "flipEGL(): " + e);
        for (StackTraceElement s : e.getStackTrace()) {
            Log.v("SDL", s.toString());
        }
    }
}