Proper way of handling exception in task continuewith

后端 未结 6 1580
悲&欢浪女
悲&欢浪女 2020-12-07 22:06

Please have a look at the following code-

static void Main(string[] args)
{
    // Get the task.
    var task = Task.Factory.StartNew(() => { r         


        
6条回答
  •  南笙
    南笙 (楼主)
    2020-12-07 22:53

    Since you are using tasks you should get AggregateException which wraps all exceptions occured during execution. You see One or more errors occurred message, because it's default output of AggregateException.ToString() method.

    You need Handle method of the exception's instance.

    Also see the right approach to handle such exceptions here.

提交回复
热议问题