using System;
using System.Transactions;
public class Program
{
public static void Main()
{
try
{
using (TransactionScope scope = new TransactionScope())
{
try
{
// 报错程序1
throw new Exception("Error in program 1"); // 模拟错误
}
catch (Exception ex)
{
Console.WriteLine("内部异常捕获1: " + ex.Message);
throw new Exception("errorMessege1");
}
try
{
// 报错程序2
throw new Exception("Error in program 2"); // 模拟错误
}
catch (Exception ex)
{
Console.WriteLine("内部异常捕获2: " + ex.Message);
throw new Exception("errorMessege2");
}
// 提交事务
scope.Complete();
}
}
catch (Exception ex)
{
Console.WriteLine("外部异常捕获: " + ex.Message);
throw new Exception("errorMessege3");
}
}
}