首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >WP8 -尝试-等待方法的分析

WP8 -尝试-等待方法的分析
EN

Stack Overflow用户
提问于 2015-06-03 13:34:58
回答 1查看 316关注 0票数 1

我正在使用(成功地) Parse进行推送通知,但是我想处理的情况是,当订阅Parse服务器是不成功的(通常由于糟糕的互联网连接)。

但是,它似乎是在Parse中抛出的异常,没有处理,它最终出现在默认方法private void Application_UnhandledException(object sender, ApplicationUnhandledExceptionEventArgs e)中,这不是我想要的。

这是密码

代码语言:javascript
复制
        try
        {
            this.Startup += async (sender, args) =>
            {
                try
                {
                    // This optional line tracks statistics around app opens, including push effectiveness:
                    ParseAnalytics.TrackAppOpens(RootFrame);

                    // By convention, the empty string is considered a "Broadcast" channel
                    // Note that we had to add "async" to the definition to use the await keyword
                    await ParsePush.SubscribeAsync("");
                }
                catch (Exception ex)
                {
                    Debug.WriteLine("jupiii");
                }
            };
        }
        catch (Exception ex)
        {
            Debug.WriteLine("jupiii");
        }

我知道外部的尝试-捕获是没有意义的,但我只是尝试无论如何,它没有处理那里。

如果没有internet连接,应用程序就会异常崩溃。

代码语言:javascript
复制
[Parse.ParseException] = {Parse.ParseException: Invalid response from server ---> System.ArgumentException: Input JSON was invalid.
   at Parse.Internal.Json.Parse(String input)
   at Parse.ParseClient.DeserializeJsonString(String jsonData)
   at Parse.ParseClient.<>c__DisplayCl...

我认为问题可能在异步方法中,但我正在等待它,这应该是正确的事情,如果我想要捕获异常。

全堆栈跟踪

代码语言:javascript
复制
Parse.ParseException: Invalid response from server ---> System.ArgumentException: Input JSON was invalid.
   at Parse.Internal.Json.Parse(String input)
   at Parse.ParseClient.DeserializeJsonString(String jsonData)
   at Parse.ParseClient.<>c__DisplayClassb.<RequestAsync>b__a(Task`1 t)
   --- End of inner exception stack trace ---
   at Parse.ParseClient.<>c__DisplayClassb.<RequestAsync>b__a(Task`1 t)
   at Parse.Internal.InternalExtensions.<>c__DisplayClass1`2.<OnSuccess>b__0(Task t)
   at Parse.Internal.InternalExtensions.<>c__DisplayClass7`1.<OnSuccess>b__6(Task t)
   at System.Threading.Tasks.ContinuationResultTaskFromTask`1.InnerInvoke()
   at System.Threading.Tasks.Task.Execute()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.GetResult()
   at Parse.ParseAnalytics.<>c__DisplayClass3.<<TrackAppOpens>b__2>d__5.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.AsyncMethodBuilderCore.<ThrowAsync>b__3(Object state)
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-06-03 14:40:09

我现在做了一件可怕的事情,只是为了让它发挥作用,如果你有更好的解决方案,我期待着它的到来。

代码语言:javascript
复制
    private void Application_UnhandledException(object sender, ApplicationUnhandledExceptionEventArgs e)
    {
        if (e.ExceptionObject.Message.Contains("Invalid response from server"))
        {
            e.Handled = true;
            return;
        }
        if (Debugger.IsAttached)
        {
            // An unhandled exception has occurred; break into the debugger
            Debugger.Break();
        }
    }
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/30621698

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档