打印當(dāng)前位置的堆棧信息方法如下,很類似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();
}