原来···是不是高手,看try cathch都能看出来···

先看一段代码:
View Code
 1     internal class ThrowAndThrowEx
2 {
3 public static void Test ()
4 {
5 Class1.DoSomething();
6 }
7 }
8
9
10 public class Class1
11 {
12 public static void DoSomething ()
13 {
14 try
15 {
16 Class2.DoSomething();
17 }
18 catch (Exception ex)
19 {
20 //throw;
21 throw new Exception("class1 call class2", ex);
22
23 }
24 }
25 }
26
27
28 public class Class2
29 {
30 public static void DoSomething ()
31 {
32 try
33 {
34 Class3.DoThrowOrThrowEx();
35 }
36 catch (Exception ex)
37 {
38 throw;
39 //throw ex;
40 }
41 }
42
43
44 }
45
46
47 public class Class3
48 {
49 public static void DoThrowOrThrowEx ()
50 {
51 try
52 {
53 int divider = 0;
54 int number = 5 / divider;
55 }
56 catch (Exception ex)
57 {
58 throw ex;
59 //throw;
60 }
61 }
62
63 }

 

 

如此来看 

 

可以在一些关键的分层次的地方使用:

                throw new Exception("class1 call class2", ex);

其他地方使用:

                throw;



 

posted @ 2011-11-10 15:07  ScottGu  阅读(347)  评论(0编辑  收藏  举报