usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Text;usingSystem.Threading.Tasks;/******************************************定义了一个循环,定义了一个自定义异常类*输出(如果输入1):*1*内finally*第一级错误:自定义错误1第二级错误:再一次出错*外finally*****************************************/namespaceConsoleApplication1{classProgram{staticvoidMain(string[]args){while(true){stringstr=Console.ReadLine();Console.WriteLine(str);try{try{if(str=="1"){thrownewCustomException();}}catch(CustomExceptionex){thrownewCustomException("再一次出错",ex);}finally{Console.WriteLine("内finally");}}catch(CustomExceptionex){Console.WriteLine("第一级错误:"+ex.InnerException.Message+"\t第二级错误:"+ex.Message);}catch(Exceptionex){Console.WriteLine(ex.Message);}finally{Console.WriteLine("外finally");}}}}///<summary>///自定义异常类///</summary>classCustomException:ApplicationException{publicCustomException(stringmsg="自定义错误1"):base(msg){}publicCustomException(stringmsg,ExceptioninnerException):base(msg,innerException){}}}