[New] Added StringHelper.formatException(Throwable)

This commit is contained in:
Robert von Burg 2014-01-21 07:40:27 +01:00
parent adc9e3598c
commit c969e25a85
1 changed files with 17 additions and 0 deletions

View File

@ -15,6 +15,8 @@
*/
package ch.eitchnet.utils.helper;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.io.UnsupportedEncodingException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
@ -551,6 +553,21 @@ public class StringHelper {
}
}
/**
* Formats the given {@link Throwable}'s stack trace to a string
*
* @param t
* the throwable for which the stack trace is to be formatted to string
*
* @return a string representation of the given {@link Throwable}'s stack trace
*/
public static String formatException(Throwable t) {
StringWriter stringWriter = new StringWriter();
PrintWriter writer = new PrintWriter(stringWriter);
t.printStackTrace(writer);
return stringWriter.toString();
}
/**
* Simply returns true if the value is null, or empty
*