private async void OnUnhandledException(object sender, UnhandledExceptionEventArgs unhandledExceptionEventArgs) { // Save the argument exception because it's cleared on first access var exception = unhandledExceptionEventArgs.Exception; var realException = exception is TargetInvocationException && exception.InnerException != null ? exception.InnerException : exception; var database = DatabaseService.Instance; var resource = new ResourcesService(); if (realException is SaveException) { unhandledExceptionEventArgs.Handled = true; await MessageDialogHelper.ShowActionDialog(resource.GetResourceValue("MessageDialogSaveErrorTitle"), realException.InnerException.Message, resource.GetResourceValue("MessageDialogSaveErrorButtonSaveAs"), resource.GetResourceValue("MessageDialogSaveErrorButtonDiscard"), async command => { var savePicker = new FileSavePicker { SuggestedStartLocation = PickerLocationId.DocumentsLibrary, SuggestedFileName = $"{database.Name} - copy" }; savePicker.FileTypeChoices.Add(resource.GetResourceValue("MessageDialogSaveErrorFileTypeDesc"), new List <string> { ".kdbx" }); var file = await savePicker.PickSaveFileAsync(); if (file != null) { database.Save(file); } }, null); } }