mirror of
https://github.com/AuthMe/AuthMeReloaded.git
synced 2024-11-23 18:55:11 +01:00
Created method to get an exception stack trace as a string
This commit is contained in:
parent
215fedc585
commit
da662afcf4
@ -4,6 +4,9 @@ import net.ricecode.similarity.LevenshteinDistanceStrategy;
|
||||
import net.ricecode.similarity.StringSimilarityService;
|
||||
import net.ricecode.similarity.StringSimilarityServiceImpl;
|
||||
|
||||
import java.io.PrintWriter;
|
||||
import java.io.StringWriter;
|
||||
|
||||
/**
|
||||
* Utility class for String operations.
|
||||
*/
|
||||
@ -84,4 +87,22 @@ public class StringUtils {
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a full stack trace of an exception as a string.
|
||||
*
|
||||
* @param exception The exception.
|
||||
*
|
||||
* @return Stack trace as a string.
|
||||
*/
|
||||
public static String getStackTrace(Exception exception) {
|
||||
// Create a string and print writer to print the stack trace into
|
||||
StringWriter stringWriter = new StringWriter();
|
||||
PrintWriter printWriter = new PrintWriter(stringWriter);
|
||||
|
||||
// Print the stack trace into the print writer
|
||||
exception.printStackTrace(printWriter);
|
||||
|
||||
// Return the result as a string
|
||||
return stringWriter.toString();
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user