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.varaneckas.hawkscope.Version.java

/**
 * Formats bug report from exception//  w w  w  .ja  v  a 2 s .c o m
 * 
 * @param e cause of possible bug
 * @return formatted report
 */
public static String getBugReport(final Throwable e) {
    final StringBuilder sb = new StringBuilder(300);
    final Writer stringWriter = new StringWriter();
    final PrintWriter w = new PrintWriter(stringWriter);
    e.printStackTrace(w);
    sb.append("Hawkscope Bug Report").append('\n').append(SEPARATOR)
            .append(e.getMessage().replaceAll(": ", ":\n")).append('\n').append(SEPARATOR)
            .append(stringWriter.toString()).append('\n').append(SEPARATOR).append(getEnvironmentReport());
    return sb.toString();
}

From source file:gov.nih.nci.cacisweb.util.CaCISUtil.java

/**
 * Return the string equivalent of the stack trace
 * //from  ww w  .  j a  v  a  2 s.c o m
 * @param arg0
 * @return
 */
public static String getStackTrace(Throwable arg0) {
    final Writer result = new StringWriter();
    final PrintWriter printWriter = new PrintWriter(result);
    arg0.printStackTrace(printWriter);
    return result.toString();
}

From source file:biz.source_code.miniConnectionPoolManager.TestMiniConnectionPoolManager.java

private static void threadMain(int threadNo) {
        try {//  w  ww .ja v  a  2s.  co m
            threadMain2(threadNo);
        } catch (Throwable e) {
            System.out.println("\nException in thread " + threadNo + ": " + e);
            e.printStackTrace(System.out);
            setShutdownFlag();
        }
    }

From source file:com.oracle.tutorial.jdbc.JDBCTutorialUtilities.java

public static void printSQLException(SQLException ex) {
    for (Throwable e : ex) {
        if (e instanceof SQLException) {
            if (ignoreSQLException(((SQLException) e).getSQLState()) == false) {
                e.printStackTrace(System.err);
                System.err.println("SQLState: " + ((SQLException) e).getSQLState());
                System.err.println("Error Code: " + ((SQLException) e).getErrorCode());
                System.err.println("Message: " + e.getMessage());
                Throwable t = ex.getCause();
                while (t != null) {
                    System.out.println("Cause: " + t);
                    t = t.getCause();/* w ww.j a  v a  2s .c  o  m*/
                }
            }
        }
    }
}

From source file:de.hasait.genesis.base.util.GenesisUtils.java

public static void printStackTrace(final Messager pMessager, final Element pElement, final Throwable pThrowable,
        final String pFormat, final Object... pArgs) {
    final StringWriter sw = new StringWriter();
    final PrintWriter pw = new PrintWriter(sw);
    final String message = String.format(pFormat, pArgs);
    pw.println(message);//from   w  ww.  java2s. c om
    pThrowable.printStackTrace(pw);
    pw.flush();
    pMessager.printMessage(Diagnostic.Kind.ERROR, sw.toString(), pElement);
}

From source file:com.momock.util.Logger.java

public static String getStackTrace(Throwable e) {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    PrintStream ps = new PrintStream(baos);
    e.printStackTrace(ps);
    return new String(baos.toByteArray());
}

From source file:dk.netarkivet.harvester.harvesting.frontier.FullFrontierReport.java

/**
 * Generates an Heritrix frontier report wrapper object by parsing the frontier report returned by the JMX
 * controller as a string./*  www  . jav  a 2 s.c  o m*/
 *
 * @param jobName the Heritrix job name
 * @param contentsAsString the text returned by the JMX call
 * @return the report wrapper object
 */
public static FullFrontierReport parseContentsAsString(String jobName, String contentsAsString) {

    FullFrontierReport report = new FullFrontierReport(jobName);

    // First dump this possibly huge string to a file
    File tmpDir = Settings.getFile(CommonSettings.CACHE_DIR);
    File tmpFile = new File(tmpDir, jobName + "-" + System.currentTimeMillis() + ".txt");
    try {
        tmpFile.createNewFile();
        BufferedWriter out = new BufferedWriter(new FileWriter(tmpFile));
        out.write(contentsAsString);
        out.close();
    } catch (IOException e) {
        LOG.error("Failed to create temporary file", e);
        return report;
    }

    BufferedReader br;
    try {
        br = new BufferedReader(new FileReader(tmpFile));
    } catch (FileNotFoundException e) {
        LOG.error("Failed to read temporary file", e);
        return report;
    }

    try {
        String lineToken = br.readLine(); // Discard header line
        while ((lineToken = br.readLine()) != null) {
            report.addLine(new FrontierReportLine(lineToken));
        }

        br.close();
    } catch (IOException e) {
        LOG.warn("Failed to close reader", e);
    } catch (Throwable t) {
        LOG.error(t);
        t.printStackTrace(System.err);
    } finally {
        FileUtils.remove(tmpFile);
    }

    return report;
}

From source file:com.tc.utils.StrUtils.java

public static String getStackTrace(Throwable t) throws IOException {
    StringWriter sw = new StringWriter();
    t.printStackTrace(new PrintWriter(sw));
    sw.close();/*  w  w w .j  a  va 2  s. co  m*/
    return sw.toString();
}

From source file:com.medlog.webservice.lifecycle.Security.java

public static String getStackTrace(Throwable t) {
    String stackTrace = null;/*from  w  w  w  .j  av  a2s. co  m*/
    try {
        StringWriter sw = new StringWriter();
        PrintWriter pw = new PrintWriter(sw);
        t.printStackTrace(pw);
        pw.close();
        sw.close();
        stackTrace = sw.getBuffer().toString();
    } catch (Exception ex) {
    }
    return stackTrace;
}

From source file:main.java.refinement_class.Useful.java

static public String getStackTrace(Throwable aThrowable) {
    Writer result = new StringWriter();
    PrintWriter printWriter = new PrintWriter(result);
    aThrowable.printStackTrace(printWriter);
    return result.toString();
}