From 8a193f5216016df63b0fe37aa0eb1e5a8962ceb3 Mon Sep 17 00:00:00 2001 From: AlexVallat Date: Sat, 10 Aug 2013 19:49:59 +0100 Subject: [PATCH] Better exception handling for pre-loading --- src/Kp2aBusinessLogic/database/edit/LoadDB.cs | 19 +++++++++++++++++-- src/keepass2android/PasswordActivity.cs | 8 ++++---- 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/src/Kp2aBusinessLogic/database/edit/LoadDB.cs b/src/Kp2aBusinessLogic/database/edit/LoadDB.cs index 9e71164d..015e45a2 100644 --- a/src/Kp2aBusinessLogic/database/edit/LoadDB.cs +++ b/src/Kp2aBusinessLogic/database/edit/LoadDB.cs @@ -17,6 +17,7 @@ This file is part of Keepass2Android, Copyright 2013 Philipp Crocoll. This file using System; using System.IO; +using System.Linq; using System.Threading.Tasks; using KeePassLib.Serialization; @@ -55,11 +56,25 @@ namespace keepass2android Kp2aLog.Log("KeyFileException"); Finish(false, /*TODO Localize: use Keepass error text KPRes.KeyFileError (including "or invalid format")*/ _app.GetResourceString(UiStringKey.keyfile_does_not_exist)); } - catch (Exception e) { + catch (AggregateException e) + { + string message = e.Message; + foreach (var innerException in e.InnerExceptions) + { + message = innerException.Message; // Override the message shown with the last (hopefully most recent) inner exception + Kp2aLog.Log("Exception: " + message); + } + Finish(false, "An error occured: " + message); + return; + } + catch (Exception e) + { Kp2aLog.Log("Exception: " + e.Message); Finish(false, "An error occured: " + e.Message); return; - } + } + + /* catch (InvalidPasswordException e) { finish(false, Ctx.GetString(Resource.String.InvalidPassword)); return; diff --git a/src/keepass2android/PasswordActivity.cs b/src/keepass2android/PasswordActivity.cs index 6223bf7b..013e1736 100644 --- a/src/keepass2android/PasswordActivity.cs +++ b/src/keepass2android/PasswordActivity.cs @@ -59,7 +59,7 @@ namespace keepass2android private bool _rememberKeyfile; ISharedPreferences _prefs; - private bool _started; + private bool _starting; public PasswordActivity (IntPtr javaReference, JniHandleOwnership transfer) : base(javaReference, transfer) @@ -368,7 +368,7 @@ namespace keepass2android protected override void OnStart() { base.OnStart(); - _started = true; + _starting = true; } private MemoryStream LoadDbFile() @@ -409,9 +409,9 @@ namespace keepass2android // OnResume is run every time the activity comes to the foreground. This code should only run when the activity is started (OnStart), but must // be run in OnResume rather than OnStart so that it always occurrs after OnActivityResult (when re-creating a killed activity, OnStart occurs before OnActivityResult) - if (_started) + if (_starting) { - _started = false; + _starting = false; if (App.Kp2a.DatabaseIsUnlocked) { LaunchNextActivity();