Task and exception silence

前端 未结 4 639
暗喜
暗喜 2021-02-04 04:04

Why exceptions thrown within a task are silent exception and you never know if a certain exception has been thrown

try
{

 Task task = new Task(
  () => {
            


        
4条回答
  •  清歌不尽
    2021-02-04 04:30

    I think you are not getting exception in case of Task because you are not waiting for exception in the main thread. You are just continuing. Put task.Wait() and you will get the exception in main thread.

提交回复
热议问题