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:com.hazelcast.stabilizer.Utils.java

public static String throwableToString(Throwable t) {
    StringWriter sw = new StringWriter();
    t.printStackTrace(new PrintWriter(sw));
    return sw.toString();
}

From source file:disko.DU.java

/**
 * <p>/*from  w w  w  . j a  v a  2 s .  c  o m*/
 * Print the full stack trace of a <code>Throwable</code> object into a
 * string buffer and return the corresponding string.  
 * </p>
 */
public static String printStackTrace(Throwable t) {
    if (t == null)
        return null;
    java.io.StringWriter strWriter = new java.io.StringWriter();
    java.io.PrintWriter prWriter = new PrintWriter(strWriter);
    t.printStackTrace(prWriter);
    prWriter.flush();
    return strWriter.toString();
}

From source file:ja.lingo.application.util.messages.ErrorDumper.java

public static String dump(Throwable t) {
    LOG.error("Internal error occured", t);

    String fileName = EngineFiles.calculateInWorking("log");

    try {//from  w w  w. j a va 2s.c om
        Files.ensureDirectoryExists(fileName);
    } catch (IOException e) {
        log(fileName, e, t);
    }
    fileName = new File(fileName, FILE_NAME_FORMAT.format(new Date())).toString();

    PrintStream ps = null;
    try {
        ps = new PrintStream(new FileOutputStream(fileName));
        ps.println("JaLingo Internal Error Log");
        ps.println("==========================");
        ps.println("Version  : " + JaLingoInfo.VERSION);
        ps.println("Exception: ...");
        t.printStackTrace(ps);
    } catch (IOException e) {
        log(fileName, e, t);
    } finally {
        if (ps != null) {
            ps.close();
        }
    }

    return fileName;
}