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':

Kotlin

private fun error(jsonArray: JSONArray): Boolean {
    try {
        val error = jsonArray.getJSONObject(0)
        error.getString("error")
        return true
    } catch (e: JSONException) {
        return false
    }
}

//......calling it from list or get permissions method...... \\
val jsonArray = JSONArray(cursor.getString(dataIndex))
if (error(jsonArray)) {
    println("Error: " + jsonArray.getJSONObject(0).getString("error"))
    return false
}
            

I think all is understandable


That's it! Go to the Start page