Is it a bad idea to use printStackTrace() for caugt Exceptions?

前端 未结 5 1132
無奈伤痛
無奈伤痛 2020-12-02 16:54

Is it a bad idea to use printStackTrace() in Android Exceptions like this?

} catch (Exception e) {
    e.printStackTrace();
}
5条回答
  •  遥遥无期
    2020-12-02 17:18

    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.

    Logging errors with:

    Log.e(TAG, "message", e) where the message can be an explanation of what was being attempted when the exception was thrown

    or simply Log.e(TAG, e) if you do not wish to provide any message for context

    You can then click on the log console at the bottom while running your code and easily search it using the TAG or log message type as a filter

提交回复
热议问题