
Untitled
By: a guest on
May 8th, 2012 | syntax:
None | size: 0.99 KB | hits: 14 | expires: Never
Pattern for implementing sync methods in terms of non-parallell Task (Translating/Unwrapping AggregateExceptions)
CallAsync().Wait();
}
catch( AggregateException ae)
{
throw ae.Flatten().First()
void Call( )
{
try
{
CallAsync().Wait();
}
catch ( AggregateException ex )
{
var translated = ex.InnerException ?? ex.Flatten().InnerExceptions.First();
if ( translated == null )
throw;
throw translated; }
}
Task CallAsync(){ ...
void Call()
{
try
{
CallAsync().Wait();
}
catch (AggregateException ex)
{
throw new MyConsistentWrapperException("An exception occurred while executing my workflow. Check the inner exception for more details.", ex.Flatten().InnerExceptions.First());
}
}
void Call()
{
try
{
CallAsync().Wait();
}
catch (AggregateException ex)
{
ExceptionDispatchInfo.Capture(ex.Flatten().InnerExceptions.First()).Throw();
}
}