Recently I blogged about Error reporting for Windows Phone 7 : Little Watson but when I was using it for the Slime Sweeper V2 , i realised its not as simple as copying and paste the framework over to XNA and use it. We have to introduce some extra stuffs.
I built the XNA version for it. Appreciated the help given by Konaju Games on MSDN forum here and Andy Pennell who have written the original version of Little Watson.
We have to add Microsoft.Phone and System.Windows references into the project. The codes are similar but we do not have native MessageBox.Show and Application.Current.UnhandledException in the project like what we have on Silverlight project and hence we have to add them differently to the project.
In the constructor of the game, we have to add this code.
Application.Current.UnhandledException += (s, e) =>
{
if (!System.Diagnostics.Debugger.IsAttached)
{
try
{
LittleWatson.ReportException(e.ExceptionObject, GetType().Assembly.FullName);
}
catch
{
// We do not want to throw exceptions in our exception handler
}
}
};
and as for MessageBox.Show, I am using Guide.BeginShowMessageBox method.
http://msdn.microsoft.com/en-us/library/dd940233.aspx
Guide.BeginShowMessageBox
You can download the sample code which I have built here, the button will crash the application and when you try to go into the application again from the emulator, a messagebox will appear :
http://cid-29f099c37b76ca59.office.live.com/self.aspx/Blog/Code%20Guide/Windows%20Phone%207/LittleWatsonXNA.zip
If you have any feedback or question, feel free to contact me via the contact me form or email me at [email protected]
(5) Comments
Adam
24 October 2011I was testing your xna version of little watson and discovered a scenario that causes the message box to dismiss itself. I actually was using the old version and didn't see your throw new FormatException() example and so was using this: int zero = 0; int error = 1 / zero; to get my exception. I just threw it in somewhere in my game, which was the draw method of a game screen between spriteBatch.Begin() and spriteBatch.End(). Maybe this just happens with little watson or maybe I found a bug. I don't really know a whole lot about how it works, so I just thought I'd let you know to see what you had to say on the matter. If you need to, I can give you more details on where I was using my 1/0 exception. Thanks
Adam
24 October 2011actually, I can't get it to work unless I use a button that sets of the exception like you did... I must be missing something.
Guo Hong
24 October 2011Hi Adam, I have checked and confirmed that the error you stated is there. It was a fault in the Little Watson which I wrote here. The problem exists as it is a async operation. What happen here is you can force a wait to the message box and wait for a response from the user, making the operation synchronous instead.
I managed to make it work on my sample. Let me know if you require the source project for reference. FYI, my project is writeen for WP7.0 :) Thanks!Adam
24 October 2011Sweet, I used your example and made it work for my project too. Mine's for wp7 as well!
Guo Hong
25 October 2011Glad to hear that! =)