Handling Errors


Type of errors:

Method to catch error


In page List I already provided example how to catch errors, in this page I'll give you it again.

This is just trying to get an error from JSONArray/Object by key 'error':

Java

private boolean error(JSONArray jsonArray) {
    try {
        JSONObject error = jsonArray.getJSONObject(0);
        error.getString("error");
        return true;
    } catch (JSONException e) {
        return false;
    }
}
//......calling it from list or get permissions method...... \\
JSONArray jsonArray = new JSONArray(cursor.getString(dataIndex));
if (error(jsonArray)) {
     System.out.println("Error: " + jsonArray.getJSONObject(0).getString("error"));
     return;
}
            

I think all is understandable


That's it! Go to the Start page