Exception Propagation hiểu qua cơ chế exception handling trong C#.
Trong try, khi exception xảy ra, các catch block được kiểm tra. Nếu không match, exception传播 (propagate) đến try block cấp cao hơn. Lặp lại cho đến khi bắt được. Nếu không bắt -> chương trình kết thúc.
Ví dụ nested try
using System;
using System.Text;
public class Demo {
public static void Main() {
try {
try { throw new ArgumentException(); }
catch (NullReferenceException e) { Console.WriteLine("catch one"); }
finally { Console.WriteLine("finally one"); }
}
catch (Exception e) { Console.WriteLine("catch two"); }
finally { Console.WriteLine("finally two"); }
Console.ReadLine();
}
}
Kết quả
finally one catch two finally two