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:org.doctester.rendermachine.RenderMachineImpl.java

public static String convertStackTraceIntoHtml(Throwable throwable) {

    StringWriter sw = new StringWriter();

    throwable.printStackTrace(new PrintWriter(sw));

    String exceptionAsStringRaw = sw.toString();

    String exceptionAsStringHtmlEscaped = HtmlEscapers.htmlEscaper().escape(exceptionAsStringRaw);
    exceptionAsStringHtmlEscaped = exceptionAsStringHtmlEscaped.replaceAll("\n", "<br/>");

    return exceptionAsStringHtmlEscaped;

}

From source file:at.alladin.rmbt.qos.testserver.util.TestServerConsole.java

/**
 * /*w w w  .  jav  a2 s. c o m*/
 * @param info
 * @param t
 * @param verboseLevelNeeded
 * @param service
 */
public static void errorReport(String errorReportKey, String info, Throwable t, int verboseLevelNeeded,
        TestServerServiceEnum service) {
    StringWriter stackTrace = new StringWriter();
    t.printStackTrace(new PrintWriter(stackTrace));
    if (!errorReportMap.containsKey(errorReportKey)) {
        errorReportMap.putIfAbsent(errorReportKey, new ErrorReport(
                info + ": [" + t.getClass().getCanonicalName() + " - " + t.getMessage() + "]", new Date()));
    }

    ErrorReport er = errorReportMap.get(errorReportKey);
    er.increaseCounter();

    LoggingService.fatal(t, info, service);
}

From source file:com.qpark.eip.core.failure.BaseFailureHandler.java

private static String getStackTrace(final Throwable t) {
    if (t != null) {
        Writer w = new StringWriter();
        PrintWriter pw = new PrintWriter(w);
        t.printStackTrace(pw);
        return w.toString();
    } else {/*w w w  .j a v  a 2s .  c  om*/
        return "";
    }
}

From source file:com.aptana.core.epl.downloader.RepositoryStatusHelper.java

private static void deeplyPrint(Throwable t, PrintStream strm, boolean stackTrace, int level) {
    if (t instanceof CoreException)
        deeplyPrint((CoreException) t, strm, stackTrace, level);
    else {/*from  www.  j  a v  a2 s  . com*/
        appendLevelString(strm, level);
        if (stackTrace)
            t.printStackTrace(strm);
        else {
            strm.println(t.toString());
            Throwable cause = t.getCause();
            if (cause != null) {
                strm.print("Caused by: "); //$NON-NLS-1$
                deeplyPrint(cause, strm, stackTrace, level);
            }
        }
    }
}

From source file:com.alibaba.dubbo.governance.web.common.pulltool.Tool.java

public static String toStackTraceString(Throwable t) {
    StringWriter writer = new StringWriter();
    PrintWriter pw = new PrintWriter(writer);
    t.printStackTrace(pw);
    return writer.toString();
}

From source file:com.wavemaker.common.util.StringUtils.java

public static String toString(Throwable th) {
    StringWriter sw = new StringWriter();
    PrintWriter pw = new PrintWriter(sw);
    th.printStackTrace(pw);
    String rtn = sw.toString();/* ww w .  j  a  v a2 s  .  co m*/
    pw.close();
    return rtn;
}

From source file:com.clank.launcher.swing.SwingHelper.java

/**
 * Shows an popup error dialog, with potential extra details shown either immediately
 * or available on the dialog./* w  w w  .  ja  v a 2 s  . c  om*/
 *
 * @param parentComponent the frame from which the dialog is displayed, otherwise
 *                        null to use the default frame
 * @param message the message to display
 * @param title the title string for the dialog
 * @param throwable the exception, or null if there is no exception to show
 * @see #showMessageDialog(java.awt.Component, String, String, String, int) for details
 */
public static void showErrorDialog(Component parentComponent, @NonNull String message, @NonNull String title,
        Throwable throwable) {
    String detailsText = null;

    // Get a string version of the exception and use that for
    // the extra details text
    if (throwable != null) {
        StringWriter sw = new StringWriter();
        throwable.printStackTrace(new PrintWriter(sw));
        detailsText = sw.toString();
    }

    showMessageDialog(parentComponent, message, title, detailsText, JOptionPane.ERROR_MESSAGE);
}

From source file:hudson.FunctionsTest.java

private static void assertPrintThrowable(Throwable t, String traditional, String custom) {
    StringWriter sw = new StringWriter();
    t.printStackTrace(new PrintWriter(sw));
    assertEquals(sw.toString().replace(IOUtils.LINE_SEPARATOR, "\n"), traditional);
    String actual = Functions.printThrowable(t);
    System.out.println(actual);/*w w w.j ava2  s . co  m*/
    assertEquals(actual.replace(IOUtils.LINE_SEPARATOR, "\n"), custom);
}

From source file:com.machinepublishers.jbrowserdriver.diagnostics.Test.java

private static String toString(Throwable t) {
    StringWriter writer = new StringWriter();
    t.printStackTrace(new PrintWriter(writer));
    return writer.toString().replace("\n", " ").replace("\t", " ");
}

From source file:net.pterodactylus.sone.web.ajax.JsonPage.java

/**
 * Returns a byte array containing the stack trace of the given throwable.
 *
 * @param t/*from   w  w w  .  j  a  va  2  s  .co  m*/
 *            The throwable whose stack trace to dump into an array
 * @return The array with the stack trace, or an empty array if the stack
 *         trace could not be dumped
 */
private static byte[] dumpStackTrace(Throwable t) {
    ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
    OutputStreamWriter writer = null;
    PrintWriter printWriter = null;
    try {
        writer = new OutputStreamWriter(byteArrayOutputStream, "uTF-8");
        printWriter = new PrintWriter(writer);
        t.printStackTrace(printWriter);
        byteArrayOutputStream.flush();
        return byteArrayOutputStream.toByteArray();
    } catch (IOException ioe1) {
        /* quite not possible. */
        return new byte[0];
    } finally {
        Closer.close(printWriter);
        Closer.close(writer);
        Closer.close(byteArrayOutputStream);
    }
}