what’s the difference between using try catch surrounding a function block that is called by some task and calling try/catch on task.wait(). If i take care of exceptions within the function, do i still need to worry about any exception that might occur from task.wait() ?
var factory = new TaskFactory();
task t1= factory.StartNew(() => funA();
t1.Wait();
void funcA()
{
try{..}
.
.
catch{..}
}
Or
var factory = new TaskFactory();
task t1= factory.StartNew(() => funA();
try
{
t1.Wait();
}
catch{....}
void funcA()
{
}
With the first block you provided you wouldn’t be able to catch any of these exceptions that may occur:
From
Task.Wait()documentation on MSDN