Answers for "This lets you capture an exception and re-throw it without changing the stack-trace"

C#
0

This lets you capture an exception and re-throw it without changing the stack-trace

In .NET 4.5 there is now the ExceptionDispatchInfo class.

try
{
    task.Wait();
}
catch(AggregateException ex)
{
    ExceptionDispatchInfo.Capture(ex.InnerException).Throw();
}

This works on any exception, not just AggregateException.

It was introduced due to the await C# language feature, which unwraps 
the inner exceptions from AggregateException instances in order to make 
the asynchronous language features more like the synchronous language features.
Posted by: Guest on June-20-2021

Code answers related to "This lets you capture an exception and re-throw it without changing the stack-trace"

C# Answers by Framework

Browse Popular Code Answers by Language