Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

throwing exceptions in ashynchronous callbacks..

Status
Not open for further replies.

Tokhra

Programmer
Oct 1, 2003
134
ES
Hi,

In my socket client class, im catching SocketExceptions and throwing custom exceptions to notify the "consumer", however..this is not having the desired result, im getting
"An Unhandled exception has occured" when I throw the exception, I've tried placing try/catch blocks around my BeginSomeMethod(new AsyncCallBack(SomeMethodCallBack)) but thats not where the exception is going, any ideas how I can raise exceptions in the asynchronous callback?

thanks,
Matt.
 
When consuming web services, I always put the try...catch block around the retrieval of the async result in the EndSomeMethod(IAsyncResult ar) method. This seems to catch any exception thrown by the asynchronous callback.
 
Thanks for the reply Shelton, you are right that does work. However this is for a classlib, so I need to catch the SocketException and then throw a SocketClientException (custom) to alert the consumer of the lib, rather then just reporting it to diagnostics as you would in a usual case. But as its asynchronous, I believe its on another thread, therefore theres nothing catching the thrown exception. I think I have to use an event on the main thread, and invoke it from the async callback. Im still working it out heh

Again, thanks for taking the time to reply.
Matt.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top