Here you can find the source of getStackTrace(Throwable aThrowable)
Parameter | Description |
---|---|
aThrowable | Throwable exception. |
public static String getStackTrace(Throwable aThrowable)
//package com.java2s; import java.io.PrintWriter; import java.io.StringWriter; import java.io.Writer; public class Main { /**/* ww w.ja v a2 s . c om*/ * getStackTrace:(Describe the usage of this method). * Get string of exception stack trace. * * @param aThrowable * Throwable exception. * @return String * String of exception stack trace. */ public static String getStackTrace(Throwable aThrowable) { final Writer result = new StringWriter(); final PrintWriter printWriter = new PrintWriter(result); aThrowable.printStackTrace(printWriter); return result.toString(); } /** * getStackTrace:(Describe the usage of this method). * Get string of exception stack trace. * * @author haoli * @param aThrowable * Throwable exception. * @param length * Length limit of the stack trace. * @return * String of exception stack trace. */ public static String getStackTrace(Throwable aThrowable, int length) { final Writer result = new StringWriter(); final PrintWriter printWriter = new PrintWriter(result); aThrowable.printStackTrace(printWriter); if (result.toString().length() <= length) { return result.toString(); } else { return result.toString().substring(0, length - 1); } } }