About C # Exception Handling!
Last Update:2018-12-07
Source: Internet
Author: User
1 using system;
2
3 namespace leleapplication2
4 {
5 /// <summary>
6 // Summary of class1.
7 /// </Summary>
8 class class1
9 {
10 static string [] etypes = {"NONE", "simple", "Index", "nested Index "};
11 [stathread]
12 static void main (string [] ARGs)
13 {
14 foreach (string etype in etypes)
15 {
16 try
17 {
18 console. writeline ("Main () Try block reached .");
19 console. writeline ("throwexception (\" {0} \ ") called.", etype );
20 throwexception (etype );
21 console. writeline ("Main () Try block continues .");
22}
23 catch (system. indexoutofrangeexception E)
24 {
25 console. writeline ("Main () system. indexoutofrangeexception catch" +
26 "Block reched. Message: \ n \" {0} \ "", E. Message );
27}
28 catch
29 {
30 console. writeline ("Main () General Catch Block reached .");
31}
32 finally
33 {
34 console. writeline ("Main () Finally block reached .");
35}
36 console. writeline ();
37}
38}
39 static void throwexception (string exceptiontype)
40 {
41 console. Write ("throwexception (\" {0} \ ") reached.", exceptiontype );
42 switch (exceptiontype)
43 {
44 case "NONE ":
45 console. writeline ("not throwing an exception .");
46 break;
47 case "simple ":
48 console. writeline ("throwing system. Exception .");
49 throw (new system. Exception ());
50 break;
51 Case "Index ":
52 console. writeline ("throwing system. indexoutofrangeexception .");
53 etypes [4] = "error ";
54 break;
55 case "nested Index ":
56 try
57 {
58 console. writeline ("throwexception (\" nested Index \ "):" + "tyr block reached .");
59 console. writeline ("throwexception (\" Index \ ") called .");
60 throwexception ("Index ");
61}
62 catch
63 {
64 console. writeline ("throwexception (\" nested Index \ ") General" + "Catch Block reached .");
65}
66 finally
67 {
68 console. writeline ("throwexception (\" nested Index \ ") Finally" + "Block reached .");
69}
70 break;
71}
72}
73}
74}
75
76. Handling of this exception indicates that, after an exception is generated, if no try operation is performed, the exception is returned to the upper level. If no try operation is performed, the exception is returned to the upper level. and so on. if it is caught by any Level 1, the level 1 won't get any more.