第7章 调试和异常.ppt

第7章 调试和异常

传播过程 public int DivRead() { try { int x = int.Parse(Console.ReadLine()); int y = int.Parse(Console.ReadLine()) return y / x; } catch (FormatException) { Console.WriteLine(不能除以0); } return y; } public static void Main() { try { int z = DivRead(); } catch (DivideByZeroException) { Console.WriteLine(不能除以0); } } 异常的捕获和传播 * 输入 0 异常的捕获和传播 Exception Message Source StackTrace TargetSite * 异常的捕获和传播 继承层次 * 3. throw语句   throw语句有两种使用方式: (1)直接抛出异常; (2)在出现异常时,通过含有catch块对其进行处理并使用throw语句重新把这个异常抛出并让调用这个方法的程序进行捕捉和处理。throw语句的使用语法格式如下: throw [表达式];

文档评论(0)

1亿VIP精品文档

相关文档