using System;
class A : IDisposable{
public void Dispose(){
Console.WriteLine("Dispose A");
throw new Exception();
}
}
class B : IDisposable{
public void Dispose(){
Console.WriteLine("Dispose B");
}
}
class C : IDisposable{
A a = new A();
B b = new B();
public void Dispose(){
a.Dispose();
b.Dispose();
}
}
class D : IDisposable{
A a = new A();
B b = new B();
public void Dispose(){
using(a)
using(b)
{}
}
}
class E : IDisposable{
A a = new A();
B b = new B();
public void Dispose(){
try{a.Dispose();}finally{
try{b.Dispose();}finally{
}
}
}
}
public class Test{
public static void Main(){
try{
using(C c = new C()){
Console.WriteLine("using C");
}
}
catch(Exception e){Console.WriteLine("catch");}
Console.WriteLine("------------");
try{
using(D d = new D()){
Console.WriteLine("using D");
}
}
catch(Exception e){Console.WriteLine("catch");}
Console.WriteLine("------------");
try{
using(E e = new E()){
Console.WriteLine("using E");
}
}
catch(Exception e){Console.WriteLine("catch");}
}
}
dXNpbmcgU3lzdGVtOwoKY2xhc3MgQSA6IElEaXNwb3NhYmxlewogIHB1YmxpYyB2b2lkIERpc3Bvc2UoKXsKICAgIENvbnNvbGUuV3JpdGVMaW5lKCJEaXNwb3NlIEEiKTsKICAgIHRocm93IG5ldyBFeGNlcHRpb24oKTsKICB9Cn0KCmNsYXNzIEIgOiBJRGlzcG9zYWJsZXsKICBwdWJsaWMgdm9pZCBEaXNwb3NlKCl7CiAgICBDb25zb2xlLldyaXRlTGluZSgiRGlzcG9zZSBCIik7CiAgfQp9CgpjbGFzcyBDIDogSURpc3Bvc2FibGV7CiAgQSBhID0gbmV3IEEoKTsKICBCIGIgPSBuZXcgQigpOwogIHB1YmxpYyB2b2lkIERpc3Bvc2UoKXsKICAgIGEuRGlzcG9zZSgpOwogICAgYi5EaXNwb3NlKCk7CiAgfQp9CgpjbGFzcyBEIDogSURpc3Bvc2FibGV7CiAgQSBhID0gbmV3IEEoKTsKICBCIGIgPSBuZXcgQigpOwogIHB1YmxpYyB2b2lkIERpc3Bvc2UoKXsKICAgIHVzaW5nKGEpCiAgIC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