110,533
社区成员
发帖
与我相关
我的任务
分享
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
namespace NestedException
{
class Program
{
static void Main(string[] args)
{
try //Level1
{
try //Level2
{
try //Level3
{
//throw new Exception1();
//throw new Exception2();
//throw new Exception3();
//throw new InvalidOperationException();
}
catch (InvalidOperationException)
{
/// 专为InvalidOperationException异常,定制的处理语句
Console.WriteLine("\n在Level3中执行InvalidOperationException ");
}
catch (Exception3) //Level3
{
Console.WriteLine("\n在Level3中执行Exception3 ");
}
finally //Level3
{
Console.WriteLine("\n在Level3中执行finally ");
}
}
catch (Exception2) //Level2
{
Console.WriteLine("\n在Level2中执行Exception2 ");
}
finally //Level2
{
Console.WriteLine("\n在Level2中执行finally ");
}
}
catch (Exception1) //Level1
{
Console.WriteLine("\n在Level1中执行Exception1 ");
}
catch (Exception ex)
{
Console.WriteLine("\n在Level1中执行Exception,注意是Exception ");
Console.WriteLine(ex);
}
finally
{
Console.WriteLine("\n在Level1中执行finally ");
}
Console.ReadKey();//程序暂停
}
}
class Exception1 : Exception
{
}
class Exception2 : Exception
{
}
class Exception3 : Exception
{
}
}