Example usage for java.lang Throwable printStackTrace

List of usage examples for java.lang Throwable printStackTrace

Introduction

In this page you can find the example usage for java.lang Throwable printStackTrace.

Prototype

public void printStackTrace(PrintWriter s) 

Source Link

Document

Prints this throwable and its backtrace to the specified print writer.

Usage

From source file:Main.java

/**
 * make throwable to string./*from  w  ww.  jav  a2  s  .c om*/
 */
public static String toString(Throwable throwable) {
    StringWriter stringWriter = new StringWriter();
    PrintWriter printWriter = new PrintWriter(stringWriter);
    printWriter.print(throwable.getClass().getName() + ": ");
    if (throwable.getMessage() != null) {
        printWriter.print(throwable.getMessage() + "\n");
    }
    printWriter.println();
    try {
        throwable.printStackTrace(printWriter);
        return stringWriter.toString();
    } finally {
        printWriter.close();
    }
}

From source file:dk.nsi.haiba.minipasconverter.executor.MinipasPreprocessor.java

public static String getStackTrace(final Throwable throwable) {
    final StringWriter sw = new StringWriter();
    final PrintWriter pw = new PrintWriter(sw, true);
    throwable.printStackTrace(pw);
    return sw.getBuffer().toString();
}

From source file:bin.spider.frame.uri.TextUtils.java

/**
 * @param message Message to put at top of the string returned. May be
 * null.//from w ww.  j a  v  a2 s  .  c o m
 * @param e Exception to write into a string.
 * @return Return formatted string made of passed message and stack trace
 * of passed exception.
 */
public static String exceptionToString(String message, Throwable e) {
    StringWriter sw = new StringWriter();
    if (message == null || message.length() == 0) {
        sw.write(message);
        sw.write("\n");
    }
    e.printStackTrace(new PrintWriter(sw));
    return sw.toString();
}

From source file:com.googlecode.icegem.cacheutils.Launcher.java

/**
 * Prints debug information if debug is enabled.
 * //  ww  w.  j  a v  a 2  s .c o  m
 * @param message
 *            - Debug message.
 * @param t
 *            - Instance of Throwable.
 */
private static void debug(String message, Throwable t) {
    if (debugEnabled) {
        System.err.println("0 [Launcher] " + message);

        if (t != null) {
            t.printStackTrace(System.err);
        }
    }
}

From source file:com.heliosapm.tsdblite.handlers.websock.WebSocketServerHandler.java

private static void sendWebSockError(final ChannelHandlerContext ctx, final Number rid, final String session,
        final String error, final Throwable t) {
    final String ts;
    if (t != null) {
        final StringWriter sw = new StringWriter();
        final PrintWriter pw = new PrintWriter(sw, true);
        sw.flush();//from  w w w.  j a  va 2  s.  com
        t.printStackTrace(pw);
        ts = sw.toString();
    } else {
        ts = null;
    }

    ctx.writeAndFlush(new TextWebSocketFrame(JSON.serializeToBuf(
            FluentMap.newMap(MapType.LINK, String.class, Object.class).fput("error", error).fput("rid", rid)
                    .sfput("session", session).sfput("trace", ts).asMap(LinkedHashMap.class))));

}

From source file:org.apache.asterix.api.http.server.ResultUtil.java

/**
 * Extract the full stack trace:/*from   w w w. j  a va  2s .  c o  m*/
 *
 * @param e
 * @return the string containing the full stack trace of the error.
 */
public static String extractFullStackTrace(Throwable e) {
    StringWriter stringWriter = new StringWriter();
    PrintWriter printWriter = new PrintWriter(stringWriter);
    e.printStackTrace(printWriter);
    return stringWriter.toString();
}

From source file:com.atlassian.theplugin.idea.ui.DialogWithDetails.java

public static String getExceptionString(Throwable t) {
    StringWriter sw = new StringWriter();
    if (t != null) {
        t.printStackTrace(new PrintWriter(sw));
    }//  w  ww.java  2  s  .  co  m
    return sw.getBuffer().toString();
}

From source file:com.netscape.cmscore.util.Debug.java

/**
 * Print the stack trace of the named exception
 * to the debug printstream/*from   w w w.java 2s .c  o m*/
 */
public static void printStackTrace(Throwable e) {
    if (!TRACE_ON)
        return;
    if (mOut == null)
        return;

    e.printStackTrace(mOut);
}

From source file:edu.uci.ics.asterix.result.ResultUtils.java

/**
 * Extract the full stack trace:/*from   w  ww.j  a  v a2s  .c o  m*/
 *
 * @param e
 * @return the string containing the full stack trace of the error.
 */
private static String extractFullStackTrace(Throwable e) {
    StringWriter stringWriter = new StringWriter();
    PrintWriter printWriter = new PrintWriter(stringWriter);
    e.printStackTrace(printWriter);
    return stringWriter.toString();
}

From source file:edu.temple.cis3238.wiki.utils.StringUtils.java

/**
 * Stores stack track as String/* w  w w. j  a  va 2 s  . co m*/
 *
 * @param exception Thrown
 * @return String containing stack trace.
 */
public static final String throwableStackTraceToString(final Throwable exception) {
    if (exception != null) {

        final StringWriter stringWriter = new StringWriter();
        exception.printStackTrace(new PrintWriter(stringWriter));
        return stringWriter.toString();
    } else {
        LOG.warning("Exception null printing stack track");
        return "";
    }
}