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

public static String getStackTrace(Throwable exception) {
    StringWriter sw = new StringWriter();
    PrintWriter pw = new PrintWriter(sw);
    exception.printStackTrace(pw);
    return sw.toString();

}

From source file:Main.java

/**
 * Get the Stack trace from throwable instance.
 *
 * @param t Exception to be print.//  ww w  .j  a va2s .  c o  m
 * @return String formed stack Trace.
 */
public static String getStack(Throwable t) {
    if (t == null)
        return null;
    StringWriter sw = new StringWriter();
    t.printStackTrace(new PrintWriter(sw));
    return sw.toString();
}

From source file:Main.java

/**
 * get stack trace as string//from w  w  w.j a va 2 s  .  co  m
 * 
 * @param traceElements
 *            - stack trace elements
 * @return built string
 */
public static String getStackTrace(Throwable throwable) {
    StringWriter sw = new StringWriter();
    PrintWriter pw = new PrintWriter(sw);
    throwable.printStackTrace(pw);
    String string = sw.toString();
    return string;
}

From source file:Main.java

public static String getErrorInfo(Throwable arg1) {
    Writer writer = new StringWriter();
    PrintWriter pw = new PrintWriter(writer);
    arg1.printStackTrace(pw);
    pw.close();//w w w .j  a va 2  s. c o m
    String error = writer.toString();
    return error;
}

From source file:Main.java

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

From source file:com.dianping.lion.util.ThrowableUtils.java

public static String extractStackTrace(Throwable t) {
    StringWriter me = new StringWriter();
    PrintWriter pw = new PrintWriter(me);
    t.printStackTrace(pw);
    pw.flush();/* ww  w  .  j a  v a  2  s  .  c  om*/
    return me.toString();
}

From source file:StringUtils.java

/**
 * Make a string representation of the exception.
 * @param e The exception to stringify//from  w w  w  .j  a  va  2s.  c om
 * @return A string with exception name and call stack.
 */
public static String stringifyException(Throwable e) {
    StringWriter stm = new StringWriter();
    PrintWriter wrt = new PrintWriter(stm);
    e.printStackTrace(wrt);
    wrt.close();
    return stm.toString();
}

From source file:com.dianping.lion.util.ThrowableUtils.java

public static String extractStackTrace(Throwable t, int maxLen) {
    StringWriter me = new StringWriter();
    PrintWriter pw = new PrintWriter(me);
    t.printStackTrace(pw);
    pw.flush();//w w w.  j ava  2s.  c  o m
    return StringUtils.substring(me.toString(), 0, maxLen);
}

From source file:com.autentia.intra.util.BeanUtils.java

/**
 * Devuelve la pila de una excepcion/*from  ww  w.j  a  va  2s.co m*/
 *
 * @param ex la excepcion
 * @return la pila de la excepcion
 */
public static String getErrorDesc(Throwable ex) {
    StringBuffer sb = new StringBuffer();
    StringWriter sw = new StringWriter();
    ex.printStackTrace(new PrintWriter(sw));
    sb.append(sw.toString());
    return sb.toString();
}

From source file:fm.last.util.StringUtils.java

/**
 * Extracts the stack trace from the passed exception into a string.
 * //from w w  w.  jav  a  2  s  . co  m
 * @param t Throwable to extract stack trace from.
 * @return String representation of the stack trace.
 */
public static String extractStackTraceString(Throwable t) {
    StringWriter sw = new StringWriter();
    t.printStackTrace(new PrintWriter(sw));
    return sw.toString();
}