APISonar


android.util.Log.setWtfHandler

> android > util > Log > setWtfHandler
android APIs util APIs Log APIs setWtfHandler APIs

Example 1
private TerribleFailure suppressAndReturnWtf(Runnable r) {
        TerribleFailure[] captured = new TerribleFailure[1];
        TerribleFailureHandler prevWtfHandler = Log.setWtfHandler((t, w, s) -> captured[0] = w);
        try {
            r.run();
        } finally {
            Log.setWtfHandler(prevWtfHandler);
        }
        return captured[0];
    }
Example 2
public void handleWtfs() {
        if (WTFS_SHOULD_CRASH && !mWtfsSet) {
            mWtfsSet = true;
            Log.setWtfHandler(new Log.TerribleFailureHandler() {
                @Override
                public void onTerribleFailure(String tag, Log.TerribleFailure what,
                        boolean system) {
                    throw new PluginManagerImpl.CrashWhilePluginActiveException(what);
                }
            });
        }
    }
Example 3
public void onCreate(Bundle arguments) {
        if (TestableLooper.HOLD_MAIN_THREAD) {
            sManager = new MainLooperManager();
            Log.setWtfHandler((tag, what, system) -> {
                if (system) {
                    Log.e(TAG, "WTF!!", what);
                } else {
                    // These normally kill the app, but we don't want that in a test, instead we want
                    // it to throw.
                    throw new RuntimeException(what);
                }
            });
        }
        super.onCreate(arguments);
    }