Handling Errors
Type of errors:
- ERR_01: No permission to access external storage - Missing permissions for Croissant app
- ERR_02: Incorrect path provided - Incorrect path of directory/file
- ERR_03: Unknown command - You provide incorrect command
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