/* 4. ´ÙÀ½ ÇÁ·Î±×·¥ÀÇ Ãâ·ÂÀ» ½á¶ó. */ #include #include int number[5] = { 1, 2, 3, 4, 5 }; // ¿©±â¸¦ ¹Ù²Ü °Í class Ex { public: int x; Ex(int i) { x = i; } }; class X { public: int a; int b; X(int x,int y) { a = x; b = -y; } void foo(int i) { if (i == i/2*2) throw 1; if (i+5 >= a) throw "2"; i = -100 * i; if (i < b) throw new Ex(3); } void gee(int i) { printf("data = %d\n",i); } }; void main() { X data(10,10); for(int i = 0; i < 5; i++) { try { data.foo(number[i]); data.gee(number[i]); } catch(int ex) { printf("%d\n",ex); } catch(char *ex) { printf("%s\n",ex); } catch(Ex *ex) { printf("%d\n",ex->x); } } }