1 public class person
2 {
3 private int _ age;
4 Public int age
5 {
6 set {
7 if (value <0 | value> 150)
8 {
9 throw new ageformatexception ("the age input is incorrect! ");
10}
11 else
12 {
13 This. _ age = value;
14}
15}
16 get {return this. _ age ;}
17}
18 public class ageformatexception: formatexception // custom exception
19 {
20 public ageformatexception ()
21: Base ()
22 {}
23 public ageformatexception (string message)
24: Base (Message)
25 {}
26
27}
28 public static void main (string [] ARGs)
29 {
30 person P = new person ();
31 While (true)
32 {
33 try
34 {
35 console. writeline ("Enter age :");
36 int intage = convert. toint32 (console. Readline ());
37 p. Age = intage;
38 console. writeline ("this person's age:" + P. Age );
39}
40 catch (overflowexception oex)
41 {
42 throw oex;
43}
44 catch (formatexception Fex)
45 {
46 throw Fex;
47}
48 catch (exception ex)
49 {
50 throw ex;
51}
52}
53}
54}