我有一个简单的异步方法,它使用 LoadAsync 异步加载实体。我无法捕获异步调用引发的异常。调试只会导致“用户代码未处理 AggregateException。” 我正在使用 RavenDB 客户端 2.0.2375。
我怎样才能捕捉到这些异常?
这是方法:
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;
}
}
}
编辑
这是一个例外:
System.AggregateException 未被用户代码处理 HResult=-2146233088 消息=发生了一个或多个错误。Source=mscorlib StackTrace:在 System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions) at System.Threading.Tasks.Task 1.GetResultCore(Boolean waitCompletionNotification)
at System.Threading.Tasks.Task
1.get_Result() at Raven.Client.Connection.HttpJsonRequest.<>c_ DisplayClassc.b _9()在 c:\Builds\RavenDB-Stable\Raven.Client.Lightweight\Connection\HttpJsonRequest.cs:第 128 行,1 getResponse) in c:\Builds\RavenDB-Stable\Raven.Client.Lightweight\Connection\HttpJsonRequest.cs:line 351
at Raven.Client.Connection.HttpJsonRequest.<InternalReadResponseStringAsync>b__8(Task
位于 c:\Builds\RavenDB-Stable\Raven 中的 Raven.Client.Connection.HttpJsonRequest.ReadJsonInternal(Func 1 task) .Client.Lightweight\Connection\HttpJsonRequest.cs:System.Threading.Tasks.ContinuationResultTaskFromResultTask 的第 128 行2.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.TaskFactory
1.FromAsyncCoreLogic(IAsyncResult iar,Func2 endFunction, Action
1 endAction, Task`1 承诺, Boolean requiresSynchronization) InnerException: