简体   繁体   中英

How can I get the type of thrown exception from CompletedEventArgs?

I use C# and Visual Studio 2012 to develop a WP8 application. I added a service reference to my project (Add Service Reference). So I am able to use webservice functions.

client = new YChatWebService.WebServiceControllerPortTypeClient();

client.getDataCompleted += client_getDataCompleted;
client.InnerChannel.OperationTimeout = new TimeSpan(0, 0, 0, 0, 500);
client.getDataAsync(); 

void client_getDataCompleted(object sender, getDataCompletedEventArgs e)
{
    // e.Error.Message

}

I have set up a timeout limit 500ms for getData() ; If the time limit is exceeded then I get following error:

"The HTTP request to 'http://example.com/webService/index?ws=1' has exceeded the allotted timeout. The time allotted to this operation may have been a portion of a longer timeout."

That is nice :) However, I would like to find out what kind of exception was thrown. Something like a string variable containing a string " TimeoutException " would be nice. How can I achive that?

You could use

if( e.Error is TimeoutException )

To see if the Exception is of the type TimeoutException

Isn't this more that the http response from the server contains the error description, not a .net exception?

Does the e.Error class have any other properties other than 'Message'? If the server is also .net, then you might be able to match the exception type, but if it's not .net they won't correspond.

If there is an error code returned, I would just use this, or just search for the text 'exceeded the allotted timeout', to confirm that it was a timeout exception.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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