From d7ff2d77e36b55b1d798b7a9fcdc4c28c2d51ea4 Mon Sep 17 00:00:00 2001 From: dankito Date: Sat, 17 Oct 2020 02:21:37 +0200 Subject: [PATCH] Implemented catching exceptions that occur in listeners --- .../banking/ui/presenter/BankingPresenter.kt | 24 ++++++++++++++----- 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/ui/BankingUiCommon/src/commonMain/kotlin/net/dankito/banking/ui/presenter/BankingPresenter.kt b/ui/BankingUiCommon/src/commonMain/kotlin/net/dankito/banking/ui/presenter/BankingPresenter.kt index 36283929..758e5be3 100644 --- a/ui/BankingUiCommon/src/commonMain/kotlin/net/dankito/banking/ui/presenter/BankingPresenter.kt +++ b/ui/BankingUiCommon/src/commonMain/kotlin/net/dankito/banking/ui/presenter/BankingPresenter.kt @@ -1029,8 +1029,12 @@ open class BankingPresenter( protected open fun callBanksChangedListeners() { val banks = ArrayList(this.allBanks) - ArrayList(banksChangedListeners).forEach { - it(banks) + ArrayList(banksChangedListeners).forEach { listener -> + try { + listener(banks) + } catch (e: Exception) { + log.error(e) { "Could not call BanksChanged listener $listener" } + } } } @@ -1044,8 +1048,12 @@ open class BankingPresenter( } protected open fun callRetrievedAccountTransactionsResponseListener(response: GetTransactionsResponse) { - ArrayList(retrievedAccountTransactionsResponseListeners).forEach { - it(response) + ArrayList(retrievedAccountTransactionsResponseListeners).forEach { listener -> + try { + listener(response) + } catch (e: Exception) { + log.error(e) { "Could not call RetrievedAccountTransactionsResponse listener $listener" } + } } } @@ -1061,8 +1069,12 @@ open class BankingPresenter( protected open fun callSelectedAccountsChangedListeners(selectedAccounts: List) { val accounts = ArrayList(selectedAccounts) - ArrayList(selectedAccountsChangedListeners).forEach { - it(accounts) + ArrayList(selectedAccountsChangedListeners).forEach { listener -> + try { + listener(accounts) + } catch (e: Exception) { + log.error(e) { "Could not call SelectedAccountsChanged listener $listener" } + } } }