using System.Runtime.ExceptionServices;
public static void Main()
Exception exception = null;
Exception exception2 = null;
var resource = new Resource();
Console.WriteLine("Using");
throw new Exception("Using failed");
if(resource != null) resource.Dispose();
if(exception != null && exception2 != null){
throw new AggregateException(exception, exception2);
}else if(exception != null){
ExceptionDispatchInfo.Capture(exception).Throw();
}else if(exception2 != null){
ExceptionDispatchInfo.Capture(exception2).Throw();
public class Resource : IDisposable {
Console.WriteLine("Disposing");
throw new Exception("Disposing failed");