-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added StackTraceUtils (renaming misnamed StackTraceUtilsTest in the p…
…rocess)
- Loading branch information
1 parent
2967718
commit f946045
Showing
7 changed files
with
57 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
vcell-util/src/main/java/org/vcell/util/StackTraceUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package org.vcell.util; | ||
|
||
import java.io.PrintWriter; | ||
import java.io.StringWriter; | ||
|
||
public class StackTraceUtils { | ||
public static String getStackTrace(Throwable throwable) { | ||
StringWriter out = new StringWriter(); | ||
PrintWriter pw = new PrintWriter(out); | ||
Throwable t = throwable; | ||
while (t != null) { | ||
t.printStackTrace(pw); | ||
t = t.getCause( ); | ||
} | ||
pw.close(); | ||
return out.getBuffer().toString(); | ||
} | ||
|
||
/** | ||
* @return String for current stack trace | ||
*/ | ||
public static String getStackTrace() { | ||
StackTraceElement[] stackTraceArray = Thread.currentThread().getStackTrace(); | ||
StringBuilder sb = new StringBuilder(); | ||
//0 and 1 are "getStackTrace" -- start with callers invocation | ||
for (int i = 2; i < stackTraceArray.length; i++) { | ||
sb.append(stackTraceArray[i]); | ||
sb.append('\n'); | ||
} | ||
return sb.toString(); | ||
} | ||
|
||
/** | ||
* recursive assemble exception message | ||
* @param throwable exception / error to recursively get the message from | ||
* @return {@link Throwable#getMessage()}, recursively | ||
*/ | ||
public static String getMessageRecursive(Throwable throwable) { | ||
StringBuilder rval = new StringBuilder(throwable.getMessage()); | ||
Throwable cause = throwable.getCause(); | ||
while (cause != null) { | ||
rval.append(" caused by ").append(cause.getMessage()); | ||
cause = cause.getCause(); | ||
} | ||
|
||
return rval.toString(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
4 changes: 4 additions & 0 deletions
4
vcell-util/src/test/java/org/vcell/util/StackTraceUtilsTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
package org.vcell.util; | ||
|
||
public class StackTraceUtilsTest { | ||
} |