RuntimeException here = new RuntimeException("here");
here.fillInStackTrace();
Log.d("my_log", "Called: " + this, here);
java.util.Map<Thread, StackTraceElement[]> ts = Thread.getAllStackTraces();
StackTraceElement[] ste = ts.get(Thread.currentThread());
for (StackTraceElement s : ste) {
Log.d("my_log", s.toString());
}
本文介绍了一种在Java环境中记录运行时异常并获取当前线程堆栈跟踪的方法。通过创建RuntimeException实例,并利用Thread类的getAllStackTraces()方法来捕获所有活动线程的堆栈跟踪信息。
346

被折叠的 条评论
为什么被折叠?



