On Fri, Oct 01, 2010 at 11:51:34AM +0100, Toby Gray wrote:
> When using the threaded router with the SpinoffSimpleReadThread() I've 
> just realised that Barry::Error exceptions aren't caught by DoRead or 
> the thread function. This means that if a 
> SocketDataHandler::DataReceived() method throws something such as 
> Barry::BadSize then it'll lead to a terminate as it's an uncaught exception.

Yeah, terminate should never happen. :-)


> I think there are two options here, forbid 
> SocketDataHandler::DataReceived() implementations from throwing 
> Barry::Error exceptions or catch all Barry::Error exceptions in 
> SocketRoutingQueue::DoRead(). I would favour the latter, calling the 
> appropriate SocketDataHandler::Error() with something like the following:
> 
> if( sdh ) {
>       // unlock&  let the handler process it
>       lock.unlock();
> -     sdh->DataReceived(*buf.get());
> +     try {
> +             sdh->DataReceived(*buf.get());
> +     }
> +     catch( Barry::Error&be ) {
> +             // Pass the error direct to the handler,
> +             // this saves the need for every data handler
> +             // implementation to wrap the method with
> +             // a try catch.
> +             sdh->Error(be);
> +     }
>       return;
> }
> 
> But I can see that having SocketDataHandler implementations handling their 
> own errors entirely internally might be a better idea.


I'd prefer DoRead() to handle all its own exceptions, but only its
own exceptions, and ones it knows how to handle.  Any other exception
handling should probably be done in SimpleReadThread(), and
SimpleReadThread() should probably have a catch(...) with a large
logging message.

My reasoning is that, in theory, an application can code its own
variant of SimpleReadThread(), and it may wish to communicate errors
from its own callback functions that DoRead() calls to the read thread
by means of exceptions.  So application level exceptions should pass
right on through DoRead() and get caught in the application's
SimpleReadThread().

I'm thinking that even Usb::Error exceptions might need to be rethrown
so that SimpleReadThread() can see them.  Our SimpleReadThread() will
probably just ignore everything and log it, but other variants might
want to do something with it.

Basically, if we can recover, we should, but we shouldn't hide information
from the app, just in case it knows better than we do.

What do you think?  Over engineered?

- Chris


------------------------------------------------------------------------------
Start uncovering the many advantages of virtual appliances
and start using them to simplify application deployment and
accelerate your shift to cloud computing.
http://p.sf.net/sfu/novell-sfdev2dev
_______________________________________________
Barry-devel mailing list
Barry-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/barry-devel

Reply via email to