打印当前位置的堆栈信息方法如下,很类似java的printStaceTrace()方法。
public String printMyStatckTrace() {
Throwable throwable = new Throwable();
StackTraceElement[] stackElements = throwable.getStackTrace();
StringBuilder sb = new StringBuilder();
if (null != stackElements) {
for (int i = 0; i < stackElements.length; i++) {
sb.append(stackElements[i].getClassName());
sb.append(".").append(stackElements[i].getMethodName());
sb.append("(").append(stackElements[i].getFileName()).append(":");
sb.append(stackElements[i].getLineNumber()+")").append("\n");
}
}
return sb.toString();
}
网友评论