From 1198a8c4956f3ff67adee412c2ec541c1cd44b9e Mon Sep 17 00:00:00 2001 From: Tom Levy Date: Mon, 18 Mar 2024 14:59:31 +0000 Subject: [PATCH] Report OutOfMemoryError when importing and exporting messages When importing/exporting large files we can run out of memory, in which case we should display a toast to the user (as we do for other exceptions). Previously, the OutOfMemoryError was not caught because it inherits from Error, not from Exception. (We have to manually call .toString() because Context.showErrorToast() from Commons takes an Exception or a String, not Throwable.) --- .../org/fossify/messages/activities/SettingsActivity.kt | 4 ++-- .../kotlin/org/fossify/messages/helpers/MessagesImporter.kt | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/app/src/main/kotlin/org/fossify/messages/activities/SettingsActivity.kt b/app/src/main/kotlin/org/fossify/messages/activities/SettingsActivity.kt index a31f1eb0..454fd92d 100644 --- a/app/src/main/kotlin/org/fossify/messages/activities/SettingsActivity.kt +++ b/app/src/main/kotlin/org/fossify/messages/activities/SettingsActivity.kt @@ -134,8 +134,8 @@ class SettingsActivity : SimpleActivity() { } toast(org.fossify.commons.R.string.exporting_successful) } - } catch (e: Exception) { - showErrorToast(e) + } catch (e: Throwable) { // also catch OutOfMemoryError etc. + showErrorToast(e.toString()) } } } diff --git a/app/src/main/kotlin/org/fossify/messages/helpers/MessagesImporter.kt b/app/src/main/kotlin/org/fossify/messages/helpers/MessagesImporter.kt index 9faa06a6..6f78feb2 100644 --- a/app/src/main/kotlin/org/fossify/messages/helpers/MessagesImporter.kt +++ b/app/src/main/kotlin/org/fossify/messages/helpers/MessagesImporter.kt @@ -32,8 +32,8 @@ class MessagesImporter(private val activity: SimpleActivity) { } else { importJson(uri) } - } catch (e: Exception) { - activity.showErrorToast(e) + } catch (e: Throwable) { // also catch OutOfMemoryError etc. + activity.showErrorToast(e.toString()) } }