Skip to content

Instantly share code, notes, and snippets.

@ranjitiyer
Created August 20, 2015 19:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ranjitiyer/02078f1e5bb30ccdfddd to your computer and use it in GitHub Desktop.
Save ranjitiyer/02078f1e5bb30ccdfddd to your computer and use it in GitHub Desktop.
public class ExceptionUtils {
public static String stackTraceAsString(Exception ex) {
if (ex == null) {
return "";
}
return Arrays.asList(ex.getStackTrace())
.stream()
.reduce(
new StringBuilder(),
(builder, frame) -> {
builder.append(frame.toString());
return builder;
},
(b1, b2) -> {
return new StringBuilder(b1.toString() + "\n" + b2.toString());
})
.toString();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment