我正在使用(成功)Parse SDK进行推送通知,但我想处理情况,当订阅Parse服务器时不成功(通常是通过糟糕的互联网连接)。
然而,看起来Exception被抛入Parse SDK,没有处理,它最终以默认方法private void Application_UnhandledException(object sender, ApplicationUnhandledExceptionEventArgs e)
结束,这不是我想要的。
这是代码
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");
}
我知道外面的尝试捕获是没有意义的,但我只是尝试了它,但确定,它没有在那里处理。
没有互联网连接,应用程序崩溃,异常
[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...
我认为问题可能在async方法中,但是我在等待它,如果我想要捕获异常,这应该是正确的事情。
完整堆栈跟踪
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)
答案 0 :(得分:0)
我现在做的很糟糕只是为了让它有效,如果你有更好的解决方案,我很期待它
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();
}
}