http://www.2cto.com/kf/201504/388758.html
1、
Log.d(TAG, Log.getStackTraceString(new Throwable()));
2、
Exception e = new Exception("this is a log");
e.printStackTrace();
3、
1
2
3
4
|
// 获取当前线程的堆栈
for
(StackTraceElement i : Thread.currentThread().getStackTrace()) {
Log.i(TAG, i.toString());
}
|
4、
1
2
3
|
RuntimeException re =
new
RuntimeException();
re.fillInStackTrace();
Log.i(TAG,
"stackTrace"
, re);
|
1
2
3
4
5
6
7
8
9
10
11
12
13
|
// 主动抛出异常调试
try
{
Log.i(TAG,
"--------------------------------NullPointerException-----------1"
);
throw
new
NullPointerException();
}
catch
(NullPointerException e1) {
// TODO: handle exception
Log.i(TAG,
"--------------------------------NullPointerException"
);
Log.e(TAG, Log.getStackTraceString(e1));
// e1.printStackTrace();
}
Log.i(TAG,
"--------------------------------NullPointerException-----------end"
);
|