I have the following code. I enclosed it in a try block and “try” to catch exceptions:
try
{
var response = query.Execute() as QueryOperationResponse;
}
catch (System.Net.WebException s)
{
var se = e;
se = se + "aa";
}
catch (Exception e)
{
var a = e;
a = a + "ab";
}
When the query.Execute line executes it produces an exception and VS2010 stops on the line starting with catch (System.Net and gives the following:
System.Data.Services.Client.DataServiceQueryException was unhandled by user code
Message=An error occurred while processing this request.
Source=System.Data.Services.Client
StackTrace:
at System.Data.Services.Client.DataServiceRequest.Execute[TElement](DataServiceContext context, QueryComponents queryComponents)
at System.Data.Services.Client.DataServiceQuery`1.Execute()
When I step through I expect it to go to the code “var se = 2;” or “var a = e”. However the next line after when I step through with F11 is a jump completely out of that code block / method.
Why doesn’t the exception fall into one of the catch buckets? I am totally confused.
DataServiceQuery.Execute() is an asynchronous method, in which you will have to either pass a delegate and call e.MarkErrorAsHandled(). Exception is shown later on and it is not in the same execution pipeline.
And e.Error will contain the thrown exception.
or
Exact names must be different but they will show up on intellisense.