7.4.4 throw语句
throw语句用于在程序执行期间出现反常情况(异常)时发生信号。异常也是一个对象,该对象的类是从System.Exception派生的,如代码清单7-8所示。
代码清单7-8 throw语句
1 using System;
2
3 namespace ProgrammingCSharp4
4{
5 public class StatementSample
6{
7 static void Main()
8{
9 string result=null;
10 try
11{
12 Console.WriteLine(result.ToString());
13}
14 catch(Exception)
15{
16 throw;
17}
18}
19}
20}
关于异常的更多细节,请参阅第22章。