From c969e25a858cc026da5259a1fd68b4d84f550bf4 Mon Sep 17 00:00:00 2001 From: Robert von Burg Date: Tue, 21 Jan 2014 07:40:27 +0100 Subject: [PATCH] [New] Added StringHelper.formatException(Throwable) --- .../ch/eitchnet/utils/helper/StringHelper.java | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/main/java/ch/eitchnet/utils/helper/StringHelper.java b/src/main/java/ch/eitchnet/utils/helper/StringHelper.java index d9eea196d..db43eb557 100644 --- a/src/main/java/ch/eitchnet/utils/helper/StringHelper.java +++ b/src/main/java/ch/eitchnet/utils/helper/StringHelper.java @@ -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 *