Throw Exception if Bundle is missing the key - Android android.os

Android examples for android.os:Bundle

Description

Throw Exception if Bundle is missing the key

Demo Code

import android.os.Bundle;

public class Main{

    /**/* w ww  .j  a  va  2  s.c  o  m*/
     * Handles the logic of throwing an exception if the throwIfNotPresent is
     * true and the bundle does not contain the key.
     * @param bundle
     * @param key
     * @param throwIfNotPresent
     * @return
     */
    protected static void doThrowHelper(Bundle bundle, String key,
            boolean throwIfNotPresent) {
        if (throwIfNotPresent && !bundle.containsKey(key)) {
            throw new IllegalArgumentException("bundle does not contain: "
                    + key);
        }
    }

}

Related Tutorials