Why the put method of a JSONObject throws JSONException? : <p>I found few answers here on how to handle this exception, but there was no explanation why would this happen in the first place. I have the following code:</p>

<pre><code>for (Map.Entry&lt;String, Double&gt; entry: qosMap.entrySet()) {
        JSONObject qosEntry = new JSONObject();
        try {
            qosEntry.put(entry.getKey(), entry.getValue());
        } catch (JSONException ex) {
            Logger.getLogger(JSONUtil.class.getName()).log(Level.SEVERE, null, ex);
        }
}
</code></pre>

<p>The qosMap will never be empty, and the data in this map will always be valid. </p>

<p>What would be a case where the exception would thrown? Why do I need to have this extra code?</p>
