I have a simple async method that loads an entity asynchronously using LoadAsync. I can't catch exceptions thrown by the async call. Debugging just leads to 'AggregateException was unhandled by user code.' I'm using RavenDB Client 2.0.2375.
How can I catch these exceptions?
Here's the method:
private async Task<Dummy> GetDummyAsync(string id)
{
using (var session = docStore.OpenAsyncSession())
{
try
{
var dummy = await session.LoadAsync<Dummy>(id);
return dummy;
}
catch (Exception ex)
{
return null;
}
}
}
Edit
Here's the exception:
System.AggregateException was unhandled by user code
HResult=-2146233088
Message=One or more errors occurred.
Source=mscorlib
StackTrace:
at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions)
at System.Threading.Tasks.Task1.GetResultCore(Boolean waitCompletionNotification)
at System.Threading.Tasks.Task1.get_Result()
at Raven.Client.Connection.HttpJsonRequest.<>c_DisplayClassc.b_9() in c:\Builds\RavenDB-Stable\Raven.Client.Lightweight\Connection\HttpJsonRequest.cs:line 128
at Raven.Client.Connection.HttpJsonRequest.ReadJsonInternal(Func1 getResponse) in c:\Builds\RavenDB-Stable\Raven.Client.Lightweight\Connection\HttpJsonRequest.cs:line 351
at Raven.Client.Connection.HttpJsonRequest.<InternalReadResponseStringAsync>b__8(Task1 task) in c:\Builds\RavenDB-Stable\Raven.Client.Lightweight\Connection\HttpJsonRequest.cs:line 128
at System.Threading.Tasks.ContinuationResultTaskFromResultTask2.InnerInvoke()
at System.Threading.Tasks.Task.Execute()
InnerException: System.Net.WebException
HResult=-2146233079
Message=The remote server returned an error: (404) Not Found.
Source=System
StackTrace:
at System.Net.HttpWebRequest.EndGetResponse(IAsyncResult asyncResult)
at System.Threading.Tasks.TaskFactory1.FromAsyncCoreLogic(IAsyncResult iar, Func2 endFunction, Action1 endAction, Task`1 promise, Boolean requiresSynchronization)
InnerException:
OpenAsyncSession? What is stack trace? What is in theInnerExceptions? - YK1