Try/Catch Wrap Around Task.Run not Handling Exception

后端 未结 3 1756
故里飘歌
故里飘歌 2021-01-18 13:11

I\'ve been learning to use TPL and have an issue with an example I gathered from this article. I copy and pasted the code exactly as in the Task.Run example but get an error

3条回答
  •  悲哀的现实
    2021-01-18 13:30

    Your try/catch runs an async operation, thus does not hold the async operation, since the code is not guaranteed to be at that location when the exception is hit. Try including the try/catch within the Task.Run(() => {..});

提交回复
热议问题