在Android中用e.printStackTrace()
来源:互联网 发布:多益网络加班 编辑:程序博客网 时间:2024/05/09 01:27
Is it a bad idea to use printStackTrace() in Android Exceptions?
up vote35down votefavorite
7
Is it a bad idea to use printStackTrace() in Android Exceptions like this?
} catch (Exception e) { e.printStackTrace();}
java android exception printstacktrace
add a comment
5 Answers
activeoldestvotes
up vote22down vote
Yes, it is a bad idea. You should instead use Android's built-in log class specifically designed for these purposes: http://developer.android.com/reference/android/util/Log.html
It gives you options to log debug messages, warnings, errors etc.
add a comment
up vote26down vote
I believe this is what you need:
catch (Exception e) { Log.e(TAG,Log.getStackTraceString(e)); }
0 0
- 在Android中用e.printStackTrace()
- Android中用LogCat输出e.printStackTrace
- Android中用LogCat输出e.printStackTrace
- e.printStackTrace()
- e.printStackTrace()
- e.printStackTrace()
- e.printStackTrace() ;
- android studio如何查看 e.printStackTrace()
- Android studio 怎么看输出的e.printStackTrace()
- getInstanceCount and e.printStackTrace
- e.getMessage() 与 e.printStackTrace() 小结
- java 中的e和e.printStackTrace()方法
- 把e.printStackTrace的堆栈信息打印在log.error()中
- 把e.printStackTrace的堆栈信息打印在log.error()中
- 把e.printStackTrace的堆栈信息打印在log.error()中
- 把e.printStackTrace的堆栈信息打印在log.error()中
- 把e.printStackTrace的堆栈信息打印在log.error()中
- 把e.printStackTrace的堆栈信息打印在log.error()中
- 第一个Omnet++
- 聚类-birch(层次方法的平衡迭代规约和聚类)
- 解决ListView中getChildAt(int index)获取item的view为null的问题
- git diff
- VS奇奇怪怪的函数unsafe~
- 在Android中用e.printStackTrace()
- Spring Boot日志管理
- POJ - 1125 Stockbroker Grapevine解题报告
- linux命令英文缩写的含义(方便记忆)
- 机器学习问题解决思路
- The two numbers and return it as a linked list
- 谷歌键盘切换26键与九宫格中文输入法
- 微信小程序----关于变量对象data 和 前端wxml取后台js变量值
- 指定的域不存在,或无法联系
Log.e(TAG, "Explanation of what was being attempted when the exception was thrown", e)
. Note the third parameter. Log.e(String,String,Throwable) gets the stacktrace string from the Throwable for you. Use themessage
parameter for something meaningful. – spaaarky21 Jun 20 '14 at 23:27android.util.Log.e()
. I didn't learn that from any of the other answers. (I didn't click the link in Nailuj's answer.) – AndreKR May 5 '16 at 16:56Log
in an unusual way – using aLog
instance (I assume?) and passing the level in as a parameter. I added an answer. – spaaarky21 May 5 '16 at 18:09