![](/img/trans.png)
[英]Can you avoid Task Continuations when using async/await if you want execution to continue immediately
[英]How to avoid over-nesting exceptions when using Task continuations
在我的代码的某些部分,我有这个:
task.Exception.InnerException.InnerException.Message
在我看来这是错误的。 正常吗
起源是当我对某个任务执行ContinueWith时,但是在ContinueWith y中,如果不是成功案例,则再次抛出异常,如下所示:
t.ContinueWith(task =>
{
if (task.Exception != null) throw task.Exception;
// do something with task.Result
});
我试图仅在TaskContinuationOptions.OnlyOnRanToCompletion
情况下进行延续,但是然后不传播异常,并且将任务视为已取消而不是出错。
最简单的方法是简单地使用async / await惯用语。
try
{
await SomeTask();
await SomeOtherTask();
SomeSynchronousProcessing();
}
catch(Exception ex)
{
}
这与链接一系列任务相同,如果一个失败,则其他任务将被跳过。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.