如何理解错误发生的条件(StackTrace wp7)

本文关键字:StackTrace wp7 条件 何理解 错误 | 更新日期: 2023-09-27 18:12:41

如何从AppHub读取以下堆栈跟踪?

Frame    Image             Function                                                         Offset
0        coredll.dll       xxx_RaiseException                                               19
1        mscoree3_7.dll                                                                     520892
2        mscoree3_7.dll                                                                     461967
3        mscoree3_7.dll                                                                     534468
4                          TransitionStub                                                   0
5                          MyPlayer.AudioPivot.m_wcGetAudio_DownloadStringCompleted    172
6                          System.Net.WebClient.OnDownloadStringCompleted                   88
7                          System.Net.WebClient.DownloadStringOperationCompleted            96
8        mscoree3_7.dll                                                                     507848
9        mscoree3_7.dll                                                                     184683
10       mscoree3_7.dll                                                                     183987
11                         System.Reflection.RuntimeMethodInfo.InternalInvoke               112
12                         System.Reflection.RuntimeMethodInfo.InternalInvoke               1576
13                         System.Reflection.MethodBase.Invoke                              104
14                         System.Delegate.DynamicInvokeOne                                 564
15                         System.MulticastDelegate.DynamicInvokeImpl                       84
16                         System.Windows.Threading.DispatcherOperation.Invoke              80
17                         System.Windows.Threading.Dispatcher.Dispatch                     404
18                         System.Windows.Threading.Dispatcher.OnInvoke                     56
19                         System.Windows.Hosting.CallbackCookie.Invoke                     84
代码:

private WebClient m_wcGetAudio;
private void GetUserData()
{
    if (m_wcGetAudio == null)
    {
        m_wcGetAudio = new WebClient();
        m_wcGetAudio.DownloadStringCompleted += new DownloadStringCompletedEventHandler(m_wcGetAudio_DownloadStringCompleted);
    }
    try
    {
        m_wcGetAudio.DownloadStringAsync(Login.GetAudioUri(App.AccessToken, App.IdUser));
    }
    catch (Exception eX)
    {
        //UpdateUIStatus("Could not load user data", eX.Message);
    }
}

:

void m_wcGetAudio_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
{
    if (e.Error != null)
    {
        //UpdateUIStatus("Error loading user data", e.Error.Message);
        return;
    }
    var response = JObject.Parse(e.Result);
    if (response["response"].HasValues)
    {
        //Parse Code
    }
    //throw new NotImplementedException();
}

我的WebClient简单地得到JSON响应,并解析它。没有处理饼干。所以我不明白为什么StackTrace包含:

System.Windows.Hosting.CallbackCookie.Invoke

如何理解错误发生的条件(StackTrace wp7)

m_wcGetAudio_DownloadStringCompleted中使用try/catch块,并在将来处理那里的异常,而不是让它完全崩溃你的应用程序

try
{
    if (e.Error != null)
    {
        //UpdateUIStatus("Error loading user data", e.Error.Message);
        return;
    }
    var response = JObject.Parse(e.Result);
    if (response["response"].HasValues)
    {
        //Parse Code
    }
}
catch (Exception ex)
{
    UpdateUIStatus("Could not load user data", ex.Message);
    // Logger.LogError(ex);
}