BrianPeek.com

A Compendium of Random Uselessness
in Search

Lib should catch exceptions in OnReadData

Last post Wed, Jul 2 2008 9:59 PM by Brian Peek. 1 replies.
Page 1 of 1 (2 items)
Sort Posts: Previous Next
  • Wed, Jul 2 2008 9:18 PM

    Lib should catch exceptions in OnReadData

    It's possible for Wiimote.OnReadData to get an exception that it doesn't catch.  In particular, with the Microsoft bluetooth stack, I see an IOException here when the wiimote gets disconnected (e.g., if you walk it out of range), as well as some other weird circumstances*.  Unfortunately, when this happens, it kills my program, and there's no way I can catch the exception, since it's not in a thread I control.

    I think at the very least, OnReadData should catch all exceptions and do nothing.  That would mean the wiimote goes mysteriously silent, but my program doesn't crash, and I can detect the failure by periodically calling GetStatus.  A little better would be to not only catch the exception, but also let the client know about it, so they can notify the user or whatever.  That's the change I made in my copy of 1.5.2 -- I catch all exceptions (not just OperationCanceledException), and then signal a new event 'WiimoteDisconnected'.  I'd be happy to send you the code, though it's really a tiny change.

    * Other weird circumstance: I noticed that if I tried to connect another wiimote ("Add Bluetooth Device") while my program was running with an existing wiimote, OnReadData would get an IOException (text something like "Device is not connected"), but in fact the device was still connected, and if I restarted my program, it would happily talk to the wiimote.  On top of that, the Add Device wouldn't succeed.  That was all with the Microsoft stack.  With the WIDCOMM stack, I can add devices while others are running, and I've never seen any sort of communication errors under those or any other circumstances.  If a wiimote gets disconnected, the only way I can detect it is by calling GetStatus and catching the exception it throws when it times out waiting for a response.

  • Wed, Jul 2 2008 9:59 PM In reply to

    Re: Lib should catch exceptions in OnReadData

    Great information.  Please do pass along the mods so I can try to incorporate them into the next version.

    Thanks!

Page 1 of 1 (2 items)
Copyright (C) 2008 Brian Peek
Powered by Community Server (Commercial Edition), by Telligent Systems