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.ikon.util.StackTraceUtils.java

/**
 * Convert stack trace to String//from   w  w  w.j av  a2  s.  co m
 */
public static String toString(Throwable t) {
    StringWriter sw = new StringWriter();
    PrintWriter pw = new PrintWriter(sw);
    t.printStackTrace(pw);
    IOUtils.closeQuietly(pw);
    IOUtils.closeQuietly(sw);
    return sw.toString();
}

From source file:Main.java

/**
 * To stack trace string string./* w  w  w  . j  ava2s .  co  m*/
 *
 * @param throwable the throwable
 * @return the string
 */
public static String toStackTraceString(Throwable throwable) {
    StringWriter sw = new StringWriter();
    PrintWriter pw = new PrintWriter(sw);
    throwable.printStackTrace(pw);
    String stackTraceString = sw.toString();
    //Reduce data to 128KB so we don't get a TransactionTooLargeException when sending the intent.
    //The limit is 1MB on Android but some devices seem to have it lower.
    //See: http://developer.android.com/reference/android/os/TransactionTooLargeException.html
    //And: http://stackoverflow.com/questions/11451393/what-to-do-on-transactiontoolargeexception#comment46697371_12809171
    if (stackTraceString.length() > MAX_STACK_TRACE_SIZE) {
        String disclaimer = " [stack trace too large]";
        stackTraceString = stackTraceString.substring(0, MAX_STACK_TRACE_SIZE - disclaimer.length())
                + disclaimer;
    }
    return stackTraceString;
}

From source file:Main.java

/**
 * @param throwable//from ww  w  . jav a 2  s . c o  m
 * @return return the stack-trace
 */
public static String getStackTrace(Throwable throwable) {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    PrintStream pstream = new PrintStream(baos);
    String stack = null;
    throwable.printStackTrace(pstream);
    pstream.flush();
    stack = baos.toString();
    return stack;
}

From source file:Main.java

/**
 * dump the exception to string/*from w  w  w  .  j  a va 2 s  .co m*/
 */
public static String dumpException(Throwable throwable) {
    StringWriter stringWriter = new StringWriter(160);
    stringWriter.write(throwable.getClass().getName());
    stringWriter.write(":\n");
    throwable.printStackTrace(new PrintWriter(stringWriter));
    return stringWriter.toString();
}

From source file:com.seer.datacruncher.spring.MacrosValidateController.java

private static String getStackTrace(Throwable throwable) {
    Writer writer = new StringWriter();
    PrintWriter printWriter = new PrintWriter(writer);
    throwable.printStackTrace(printWriter);
    return writer.toString();
}

From source file:com.example.HelloWorldIntegrationTest.java

@AfterClass
public static void stopSeleniumClent() {
    try {/*from ww w  .  j  a va2 s  . co  m*/
        driver.close();
        driver.quit();
    } catch (Throwable t) {
        // Catch error & log, not critical for tests
        System.err.println("Error stopping driver: " + t.getMessage());
        t.printStackTrace(System.err);
    }
}

From source file:com.github.triceo.robozonky.notifications.email.AbstractEmailingListener.java

protected static String stackTraceToString(final Throwable t) {
    final StringWriter sw = new StringWriter();
    final PrintWriter pw = new PrintWriter(sw);
    t.printStackTrace(pw);
    return sw.toString();
}

From source file:Main.java

/**
 * Returns the output of printStackTrace as a String.
 *
 * @param e A Throwable./* w ww  .  j  a v a 2s  .  c om*/
 * @return A String.
 */
public static final String stackTrace(Throwable e) {
    String foo = null;
    try {
        // And show the Error Screen.
        ByteArrayOutputStream ostr = new ByteArrayOutputStream();
        e.printStackTrace(new PrintWriter(ostr, true));
        foo = ostr.toString();
    } catch (Exception f) {
        // Do nothing.
    }
    return foo;
}

From source file:com.joliciel.csvLearner.utils.LogUtils.java

/**
Return the current exception & stack trace as a String.
*//*from   w ww  .  j a v a2  s.co m*/
public static String getErrorString(Throwable e) {
    String s = null;
    try {
        StringWriter sw = new StringWriter();
        PrintWriter ps = new PrintWriter((Writer) sw);
        e.printStackTrace(ps);
        sw.flush();
        s = sw.toString();
        sw.close();
    } catch (IOException ioe) {
        // do nothing!
    }
    return s;
}

From source file:org.biopax.validator.api.AbstractAspect.java

private static String getStackTrace(Throwable aThrowable) {
    StringWriter strw = new StringWriter();
    PrintWriter printWriter = new PrintWriter(strw);
    aThrowable.printStackTrace(printWriter);
    return strw.toString();
}