Is there an analog of ExceptionDispatchInfo
in Microsoft.Bcl.Async? I cannot find anything similar.
This question was triggered by another question of mine. When the exception's parent task
is available, I can use task.GetAwaiter().GetResult()
to rethrow, as suggested by @StephenCleary.
What are my options for when it is not available?
I have experimented with the implementation provided by avo - yet it doesn't pass all the tests. By that I mean that it provides the basic behaviour but will fail in more complex cases (such as multiple throwing, recapturing, etc...).
As part of Theraot.Core I have made a back port of this class in such way that it will work in modern Mono, old Mono (pre 2.6*) and any Microsoft .NET from 2.0 to 4.0.
*: With a little tip from Miguel de Icaza :)
The code below is currently only on the Feature branch, it will eventually move to the master branch (along with Task for .NET 2.0 :), at which point it will available via the Theraot.Core nuget. I'm leaving it here in case somebody needs it sooner.
Bug reports are welcome on the issue tracker at the project's github (linked above), if you find any.
Here's the implementation of
ExceptionDispatchInfo
from Mono. It seems to be compatible with Microsoft .NET 4.0, as far as I have tested it.