使用printStackTrace()处理caugt异常不是一个好主意吗? [英] Is it a bad idea to use printStackTrace() for caugt Exceptions?

查看:91
本文介绍了使用printStackTrace()处理caugt异常不是一个好主意吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在这样的Android异常中使用printStackTrace()是个坏主意吗?

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

} catch (Exception e) {
    e.printStackTrace();
}


推荐答案

是的,这很糟糕理念。您应该改用专为这些目的设计的Android内置日志类: http:/ /developer.android.com/reference/android/util/Log.html

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 ),其中消息可以解释抛出异常时尝试进行的操作

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

或简单地 Log。 e(TAG,e)如果您不想为上下文提供任何消息

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

然后您可以单击底部的日志控制台在运行代码并轻松使用TAG或日志消息类型作为过滤器进行搜索

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

这篇关于使用printStackTrace()处理caugt异常不是一个好主意吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆