链式异常是处理异常的try-catch语句链。创建异常链,即链接异常-
设置第一个try-catch-
static void Main(string[] args) {
   try {
      One();
   } catch (Exception e) {
      Console.WriteLine(e);
   }
}现在在方法下尝试捕获One()-
static void One() {
   try {
      Two();
   } catch (Exception e) {
      throw new Exception("第一个例外!", e);
   }
}该方法Two()还继续链接异常。
static void Two() {
   try {
      Three();
   } catch (Exception e) {
      throw new Exception("第二个例外!", e);
   }
}现在下一个方法。
static void Three() {
   try {
      Last();
   } catch (Exception e) {
      throw new Exception("第三例外!", e);
   }
}将我们带到最后。
static void Last() {
   throw new Exception("最后的例外!");
}在运行上面的代码时,异常将像这样处理-
System.Exception: 第一个例外! ---< System.Exception: Middle Exception! ---< System.Exception: 最后的例外! at Demo.Two () [0x00000] in <199744cb72714131b4f5995ddd1a021f>:0 --- End of inner exception stack trace --- at Demo.Two () [0x00016] in <199744cb72714131b4f5995ddd1a021f>:0 at Demo.One () [0x00000] in <199744cb72714131b4f5995ddd1a021f>:0 --- End of inner exception stack trace --- at Demo.One () [0x00016] in <199744cb72714131b4f5995ddd1a021f>:0 at Demo.Main (System.String[] args) [0x00000] in <199744cb72714131b4f5995ddd1a021f>:0