Please consider the following scenario.
I have a Task, that returns an object, lets say it’s of type:
class A
{
string success;
}
Now the task’s body is for example:
{
return new A() { success = "yes" }
}
The outside of this task doesn’t matter, if it’s continous task or anything. What’s important is that on return from that task I can read this returned object by task.Result.status.
The problem I have, is that if I’d like to return the object of that kind within the try/catch block, the task.Result.status is null, and task.Result is of AggregatedException type. So for example:
//(Task body)
{
{
try
{
//something throwing exception
}
catch(Exception exc)
{
return new A() { success = "yes" }
}
}
I’m looking for a way to get that object that is returned in the catch block, when the execution returns from that task, instead of AggregatedException that I receive now.
Please, restrain yourself from the usuall forums “answers” like “why would you want it”, “what’s the point of it” etc. I’m not interested in answers like that.
If it can’t be done and you know it for a fact (maybe the tasks when throw exceptions always return AggregatedException no matter what), then please tell me so straightforward. If it can on the other hand, I’d appriciate how I can achieve that.
Lucas
Your question could be explained better but as I understand it this is pretyt much what you want to do and should work.
Exceptions caught inside a Task should not propagate up to the AggregateException. If that is still happening you are doing something wrong elsewhere in your code.