如何使用Bugsense来捕获特定代码中的异常?

本文关键字:代码 异常 Bugsense 何使用 | 更新日期: 2023-09-27 18:11:55

我将BugSense添加到我的Windows Phone应用程序中,并相应地修改了app. example .cs。然而,我知道有些用户正在经历崩溃,但BugSense没有看到它。BugSense看到新的会话和什么不是,所以我知道许可证是正确的。

我相信崩溃发生在这段代码,特别是与web客户端我认为。我可以在这段代码中添加什么,以便如果发生了什么,BugSense会报告它?

 private void LongListSelector_SelectionChanged(object sender, SelectionChangedEventArgs e)
    {
        LongListSelector selector = sender as LongListSelector;
        // verifying our sender is actually a LongListSelector
        if (selector == null)
            return;
        SoundData data = selector.SelectedItem as SoundData;
        // verifying our sender is actually SoundData
        if (data == null)
            return;

        if (data.IsDownloaded)
        {
            this.PlaySound(IsolatedStorageFile.GetUserStoreForApplication().OpenFile(data.SavePath, FileMode.Open, FileAccess.Read, FileShare.Read));
        }
        else
        {
            if (!SimpleIoc.Default.GetInstance<INetworkService>().IsConnectionAvailable)
            {
                MessageBox.Show("You need an internet connection to download this sound.");
            }
            else
            {
                WebClient client = new WebClient();
                client.DownloadProgressChanged += (senderClient, args) =>
                    {
                        Dispatcher.BeginInvoke(() =>
                            {
                                data.DownloadProgress = args.ProgressPercentage;
                            });
                    };
                client.OpenReadCompleted += (senderClient, args) =>
                {
                    using (IsolatedStorageFileStream fileStream = IsolatedStorageFile.GetUserStoreForApplication().CreateFile(data.SavePath))
                    {
                        args.Result.Seek(0, SeekOrigin.Begin);
                        args.Result.CopyTo(fileStream);
                        this.PlaySound(fileStream);
                        data.Status = DownloadStatus.Downloaded;
                    }
                    args.Result.Close();
                };
                client.OpenReadAsync(new Uri(data.FilePath));
                data.Status = DownloadStatus.Downloading;
            }
        }
        selector.SelectedItem = null;
    }

如何使用Bugsense来捕获特定代码中的异常?

我刚刚开始在我的WP8应用程序中使用BugSense,我非常印象深刻的是它如何捕获未处理的异常,而不仅仅是我的app .xaml.cs文件中的一行代码:

public App()
{
    BugSenseHandler.Instance.InitAndStartSession(new ExceptionManager(Current), RootFrame, "YourBugSenseApiKey");
    ...
}

所以从我的经验来看,BugSense应该为你捕获这些异常,而不需要任何额外的代码。

你怎么知道这些车祸?是来自Windows Phone开发中心吗?如果是这样,那么你可能仍然会看到在你添加BugSense之前安装了旧版本应用程序的用户报告崩溃。

我发现在启动时从应用程序本身检查新应用程序版本并提醒用户是让人们了解最新情况的好方法。许多用户可能长时间不访问Windows Phone Store,即使如此,他们也不会费心将你的应用更新到最新版本,所以你很有可能会有很多用户使用旧版本。