I've implemented the following code to get crash details:
Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {
@Override
public void uncaughtException(Thread thread, Throwable ex) {
Log.e(TAG, "Uncaught Exception!");
StackTraceElement stackTraceElements[] = ex.getStackTrace();
}
});
The problem I'm facing is, let's say two exceptions occur, RuntimeException
which was caused by NullPointerException
. In the above method, I'm getting trace for only RuntimeException
. What should I do to get entire the back trace?
使用getCause()方法
ex.getCause().getStackTrace()
You can use the following.
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
t.printStackTrace(pw);
sw.toString(); // stack trace as a string
This will give you the complete stack trace. For other ways of getting the same please go through this thread . Above has been copied from the same thread
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.