c#中的异常处理
2012-10-29 22:43
232 查看
class Program { static string[] eTypes = { "none", "simple", "index", "nested index" }; static void Main(string[] args) { foreach (string etype in eTypes) { try { Console.WriteLine("Main() try block reached."); Console.WriteLine("ThrowException(\"{0}\") called.", etype); ThrowException(etype); Console.WriteLine("Main() try block continues."); } catch (System.IndexOutOfRangeException e) { Console.WriteLine("Main() System.IndexOutOfRangeException catch" + "block reached.Message:\n\"{0}\"", e.Message); } catch { Console.WriteLine("Main() general catch block reached."); } finally { Console.WriteLine("Main() finally block reached."); } } Console.ReadKey(); } static void ThrowException(string etype) { // throw new NotImplementedException(); Console.WriteLine("ThrowException{\"{0}\"} reached.",etype); switch(etype) { case "none": Console.WriteLine("Not throwing an exception."); break; case "simple": Console.WriteLine("Throwing System.Exception"); throw (new System.Exception()); break; case "index": Console.WriteLine("Throwing System.IndexOutOfRangeException."); eTypes[4] = "error"; break; case "nested index": try { Console.WriteLine("ThrowException(\"nested index\") " + "try block reached."); Console.WriteLine("ThrowException(\"index\") called."); ThrowException("index"); } catch { Console.WriteLine("ThrowException(\"nested index\") general" + "catch block reached."); } finally { Console.WriteLine("ThrowException(\"nested index\") finally"+"block reached"); } break; } } }
相关文章推荐
- C#之系统异常处理机制
- C# 异常处理 <思维导图>
- C#各种异常处理方式
- C# .NET编程基础-throw异常处理-Email格式检测示例
- C# 如何处理抛出的异常,或者已知的错误
- 第五讲 C#中的异常处理
- Head First C# 中文版 第10章 异常处理 page456
- C#类库处理异常指导原则
- Head First C# 中文版 第10章 异常处理 page476
- 初探C# 异常处理
- C#中对错误(异常)的处理
- 黑马程序员----C#中的流程控制语句之异常处理语句
- C# 异常处理[转]
- 读书笔记_C#技术内幕_第十章(处理异常和错误)
- 天轰穿C# -vs2010 - 03C#的异常处理之多个catch块【原创】
- C#中unhandled异常处理的问题
- 在C#中利用Keep-Alive处理Socket网络异常断开的方法
- 在C#中利用Keep-Alive处理Socket网络异常断开的方法
- C#讲座(3)--C#中异常的处理
- 浅谈C#中简单的异常引发与处理操作