some more error handling

hauntED
yova 6 months ago
parent d306b1b50f
commit c227792cfb

@ -706,7 +706,7 @@ class MainActivity : AppCompatActivity() {
result = cursor.getString(cursor.getColumnIndex(OpenableColumns.DISPLAY_NAME));
}
} finally {
cursor!!.close();
cursor?.close();
}
}
if (result == null) {
@ -819,7 +819,7 @@ class MainActivity : AppCompatActivity() {
try {
textFile = contentResolver.openFileDescriptor(thisFileUri!!, "w")!!
textFile.checkError()
}catch (e: java.lang.IllegalArgumentException) {
} catch (e: java.lang.IllegalArgumentException) {
Log.d(javaClass.simpleName, "Problem with saving file\nBug in Android 11?\n${e.stackTraceToString()}")
this.runOnUiThread(
{
@ -834,7 +834,22 @@ class MainActivity : AppCompatActivity() {
)
return false
// TODO: implement workaround for this bug. See: https://stackoverflow.com/q/69248596
} catch (e: Exception) {
} catch (e: java.io.FileNotFoundException) {
Log.d(javaClass.simpleName, "File not found. Deleted while loaded?\n${e.stackTraceToString()}")
this.runOnUiThread(
{
Toast.makeText(
this,
"File not found. Deleted while loaded?",
Toast.LENGTH_LONG
).show()
}
)
selectFileForSaveAs()
return false
}
catch (e: Exception) {
Log.d(javaClass.simpleName, "Problem with accessing file\n${e.stackTraceToString()}")
this.runOnUiThread(
{
@ -960,7 +975,18 @@ class MainActivity : AppCompatActivity() {
}
}
}
} catch (e: Exception) {
} catch (e: java.io.FileNotFoundException) {
Log.d(javaClass.simpleName, "File not found during reading:\n${e.stackTraceToString()}")
this.runOnUiThread({
selectFileForSaveAs()
Toast.makeText(
this,
"File not found during reading.\n$e",
Toast.LENGTH_LONG
).show()
})
}
catch (e: Exception) {
Log.d(javaClass.simpleName, e.stackTraceToString())
this.runOnUiThread({
Toast.makeText(
@ -969,9 +995,6 @@ class MainActivity : AppCompatActivity() {
Toast.LENGTH_LONG
).show()
})
/*
selectFileForSaveAs()
*/
return false
}

Loading…
Cancel
Save