简体   繁体   English

使用XNA在XNA中为WP7实现全局异常处理程序

[英]Implementing a global exception handler in XNA for WP7 using XNA

I have a WP7 game that has symptoms similar to the following post: 我有一个WP7游戏,其症状类似于以下帖子:

WP7 App exits when deployed WP7 App在部署时退出

It works fine when run through the debugger on the device, but when deployed it does not run. 它在设备上运行调试器时工作正常,但在部署时它不会运行。 Also when I unplug the data connection while debugging, it runs for another 30 seconds or so and then exits! 另外,当我在调试时拔下数据连接时,它还会再运行30秒钟左右,然后退出!

So, I am trying to somehow trap the mysterious exception that I assume must be thrown at some point. 所以,我试图以某种方式捕获我认为必须在某个时刻抛出的神秘异常。

Question 1 - Where can I put a try catch block so I can trap the error? 问题1-我可以在哪里放置try catch块,以便捕获错误? Currently I have a single class derived from Game which gets executed automatically by the framework. 目前我有一个派生自Game的单一类,它由框架自动执行。

Question 2 - What is the easiest way to get the error message of the exception? 问题2-获取异常错误消息的最简单方法是什么? I am using XNA so I assume a dialog box is out of the question. 我正在使用XNA,所以我认为对话框是不可能的。

Thanks! 谢谢! swine

Q 1. 问1。
There doesn't appear to be a way to add a global exception handler to a WP7 XNA app. 似乎没有一种将全局异常处理程序添加到WP7 XNA应用程序的方法。
Where to add appropriate error handling will be dependent upon your code. 添加适当错误处理的位置取决于您的代码。 As you haven't shown any code or even described what the app/game does it's hard to say. 由于您没有显示任何代码,甚至没有描述应用程序/游戏的功能,因此很难说。 If you're using the data connectioion I'd look at the code you are using to make a network/web call. 如果您正在使用数据连接,我会查看您用于进行网络/网络呼叫的代码。 I would guess that you're not handling a connection dropping and you currently have a 30 second timeout on the request. 我猜想您没有处理掉线问题,并且当前请求有30秒的超时时间。 Hence the applicaiton crashing 30 seconds after you disconnect from the network. 因此,在断开与网络的连接后,应用程序会崩溃30秒。

Q 2. 问2。
You can show a MessageBox from XNA. 您可以显示来自XNA的MessageBox。 See http://msdn.microsoft.com/en-us/library/ff827868.aspx 请参阅http://msdn.microsoft.com/en-us/library/ff827868.aspx

You should be able to use a similar technique that we use on the Xbox 360 for Xbox LIVE Indie games. 您应该能够使用类似于Xbox 360上用于Xbox LIVE独立游戏的技术。 Nick Gravely shared the original sample here Nick Gravely在这里分享了原始样本

http://blog.nickgravelyn.com/2009/07/a-more-robust-exception-system/ http://blog.nickgravelyn.com/2009/07/a-more-robust-exception-system/

and then I enhanced his to do a little more here. 然后我增强了他的能力,可以在这里做更多的事情。

http://www.xnadevelopment.com/tutorials/tellmewhatswrong/tellmewhatswrong.shtml http://www.xnadevelopment.com/tutorials/tellmewhatswrong/tellmewhatswrong.shtml

The same technique should work on the phone. 电话上应使用相同的技术。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM