public static void CheckForPreviousException()
        {
            try
            {
                errormessage = null;
                string contents = null;
                using (var store = IsolatedStorageFile.GetUserStoreForApplication())
                {
                    if (store.FileExists(FileName))
                    {
                        using (TextReader reader = new StreamReader(store.OpenFile(FileName, FileMode.Open, FileAccess.Read, FileShare.None)))
                        {
                            contents = reader.ReadToEnd();
                        }
                        SafeDeleteFile(store);
                    }
                }

                if (contents != null)
                {
                    errormessage = JsonConvert.DeserializeObject<ErrorMessageInfo>(contents);
                }

                if (errormessage != null)
                {
                    if (MessageBox.Show(ModelText, MessageBoxTitle, MessageBoxButton.OKCancel) == MessageBoxResult.OK)
                    {
                        EmailComposeTask email = new EmailComposeTask();
                        email.To = EmailTarget;
                        email.Subject = errormessage.UserMessage;
                        email.Body = ReportContents();
                        SafeDeleteFile(IsolatedStorageFile.GetUserStoreForApplication());
                        email.Show();
                    }
                }
            }
            catch { }
        }
        public static void HandleException(Exception ex, string extra = "")
        {
            try
            {
                errormessage = new ErrorMessageInfo()
                {
                    UserMessage = string.IsNullOrEmpty(extra) ? "Unexpected error" : extra,
                    Info = string.IsNullOrEmpty(ex.Message) ? "Error message" : ex.Message,
                    Exception = ex.InnerException.ToString(),
                    ExceptionDetail = ex.StackTrace
                };

                using (var store = IsolatedStorageFile.GetUserStoreForApplication())
                {
                    SafeDeleteFile(store);
                    var jsonString = JsonConvert.SerializeObject(errormessage);
                    using (TextWriter output = new StreamWriter(store.CreateFile(FileName)))
                    {
                        output.WriteLine(jsonString);
                    }
                }
            }
            catch { }
        }