在什么情况下Android的Log.wtf终止我的应用程序? [英] Under what circumstances will Android's Log.wtf terminate my app?

查看:158
本文介绍了在什么情况下Android的Log.wtf终止我的应用程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想记录的错误报告我的应用程序到Android Market错误控制台;它看起来像我可以使用<一个href="http://developer.android.com/reference/android/util/Log.html#wtf%28java.lang.String,%20java.lang.String,%20java.lang.Throwable%29"><$c$c>Log.wtf对于这一点。

I would like to log error reports for my app to the Android Market error console; it looks like I can use Log.wtf for this.

的文档 Log.wtf 说:

什么可怕的失败:报告认为,绝不应该发生的情况。总是会在与调用堆栈级别ASSERT记录的错误。根据系统配置,报告可以加入到DropBoxManager和/或过程可以用一个错误对话框立即终止。

What a Terrible Failure: Report a condition that should never happen. The error will always be logged at level ASSERT with the call stack. Depending on system configuration, a report may be added to the DropBoxManager and/or the process may be terminated immediately with an error dialog.

在我的情况,我可以捕获这些异常,并从中恢复出显示错误信息;我不希望我的应用程序崩溃,但我不希望报告被发送到错误控制台。

In my case, I can catch these exceptions and recover from them by showing an error message; I don't want my app to crash, but I do want the report to be sent to the error console.

在什么情况下会 Log.wtf 终止我的应用程序?是否有可能得到一个错误的报告,而不会导致应用程序崩溃?

Under what circumstances will Log.wtf terminate my app? Is it possible to get an error report without causing the app to crash?

推荐答案

这取决于您的系统设置(可启用某些选项进行调试,但都在正常的设备禁用)。他们启用设置时,Android是编译的设备和可能的内核。

It depends on your system settings (certain options can be enabled for debugging but are disabled on normal devices). They are settings enabled when android is compiled for the device and possibly the kernel.

我会建议使用Log.e()以preFIX代替Log.wtf(),以避免出现任何问题如: 跆拳道:有什么可怕的事情发生

I would suggest using Log.e() with a prefix instead of Log.wtf() to avoid any problems e.g. WTF: Something terrible happened

下面是当你调用一个Log.wtf会发生什么()

Here is what happens when you call a Log.wtf()

- > Log.java

-> Log.java

/**
 * What a Terrible Failure: Report an exception that should never happen.
 * Similar to {@link #wtf(String, Throwable)}, with a message as well.
 * @param tag Used to identify the source of a log message.
 * @param msg The message you would like logged.
 * @param tr An exception to log.  May be null.
 */
public static int wtf(String tag, String msg, Throwable tr) {
    TerribleFailure what = new TerribleFailure(msg, tr);
    int bytes = println_native(LOG_ID_MAIN, ASSERT, tag, getStackTraceString(tr));
    sWtfHandler.onTerribleFailure(tag, what);
    return bytes;
}

- > Log.java

-> Log.java

private static TerribleFailureHandler sWtfHandler = new TerribleFailureHandler() {
        public void onTerribleFailure(String tag, TerribleFailure what) {
            RuntimeInit.wtf(tag, what);
        }
    };

- > RuntimeInit.java

-> RuntimeInit.java

/**
 * Report a serious error in the current process.  May or may not cause
 * the process to terminate (depends on system settings).
 *
 * @param tag to record with the error
 * @param t exception describing the error site and conditions
 */
public static void wtf(String tag, Throwable t) {
    try {
        if (ActivityManagerNative.getDefault()
                .handleApplicationWtf(mApplicationObject, tag,
                        new ApplicationErrorReport.CrashInfo(t))) {
            // The Activity Manager has already written us off -- now exit.
            Process.killProcess(Process.myPid());
            System.exit(10);
        }
    } catch (Throwable t2) {
        Slog.e(TAG, "Error reporting WTF", t2);
    }
}

- > ActivityManagerNative.java

-> ActivityManagerNative.java

public boolean handleApplicationWtf(IBinder app, String tag,
        ApplicationErrorReport.CrashInfo crashInfo)
        throws RemoteException {
    Parcel data = Parcel.obtain();
    Parcel reply = Parcel.obtain();
    data.writeInterfaceToken(IActivityManager.descriptor);
    data.writeStrongBinder(app);
    data.writeString(tag);
    crashInfo.writeToParcel(data, 0);
    mRemote.transact(HANDLE_APPLICATION_WTF_TRANSACTION, data,
            reply, 0);
    reply.readException();
    boolean res = reply.readInt() != 0;
    reply.recycle();
    data.recycle();
    return res;
} 

这篇关于在什么情况下Android的Log.wtf终止我的应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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