Advertisement
Guest User

Untitled

a guest
May 24th, 2016
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.86 KB | None | 0 0
  1. #include <iostream>
  2. #include <conio.h>
  3. #include <string>
  4. #include <string.h>
  5. using namespace std;
  6.  
  7. void foo1(int god) { //funkcuya bez isklycheniy
  8. cout<<"Funkcuya bez obrabotki isklycheniy!"<<endl;
  9. if (god % 100 == 0 && god % 400 == 0)
  10. cout << "God vusokosnuy!" << endl;
  11. else if (god % 100 != 0 && god % 4 == 0)
  12. cout << "God vusokosnui!" << endl;
  13. else
  14. cout << "God ne vusokosnui!" << endl;
  15. }
  16.  
  17. void foo2(int god) {//so specufikacuey throw
  18. try {
  19. if (god < 0)
  20. throw 1;
  21. }
  22. catch (int) {
  23. cout<<"Fukcuya so specufikacuey throw!"<<endl;
  24. };
  25. if (god % 100 == 0 && god % 400 == 0)
  26. cout << "God vusokosnuy!" << endl;
  27. else if (god % 100 != 0 && god % 4 == 0)
  28. cout << "God vusokosnui!" << endl;
  29. else
  30. cout << "God ne vusokosnui!" << endl;
  31. }
  32.  
  33. void foo3(int god) { //s konkretnoy specufikacuey s podoxodyashim standratnum isklycheniem
  34. try {
  35. if (god < 0)
  36. throw god;
  37. }
  38. catch (int n) {
  39. cout << "God ne mojet but` prinimat` znachenie "<< n << endl;
  40. cout<<"Isklychenie so specufikacuey s podxodyashim standartnum isklycheniem"<<endl;
  41. };
  42. if (god % 100 == 0 && god % 400 == 0)
  43. cout << "God vusokosnuy!" << endl;
  44. else if (god % 100 != 0 && god % 4 == 0)
  45. cout << "God vusokosnui!" << endl;
  46. else
  47. cout << "God ne vusokosnui!" << endl;
  48. }
  49.  
  50. class MyEx {
  51. public:
  52. MyEx(){};
  53. };
  54.  
  55. void foo4(int god) {//isklychenie pyustum klassom
  56. try {
  57. if (god < 0)
  58. throw MyEx();
  59. }
  60. catch (MyEx) {
  61. cout << "Oshubka bula zgenerirovana pystum klassom isklycheniy!" << endl;
  62. };
  63. if (god % 100 == 0 && god % 400 == 0)
  64. cout << "God vusokosnuy!" << endl;
  65. else if (god % 100 != 0 && god % 4 == 0)
  66. cout << "God vusokosnui!" << endl;
  67. else
  68. cout << "God ne vusokosnui!" << endl;
  69. }
  70. class MyExWithParam {
  71. public:
  72. string param;
  73. string returnParam(){return param;};
  74. MyExWithParam(string str) :
  75. param(str)
  76. {};
  77. };
  78.  
  79. void foo5(int god) {
  80. try {
  81. if (god < 0)
  82. throw new MyExWithParam("Isklychenie s polyami-parametrami!");
  83. }
  84. catch (MyExWithParam *a) {
  85. cout<<a->param<<endl;
  86. };
  87. if (god % 100 == 0 && god % 400 == 0)
  88. cout << "God vusokosnuy!" << endl;
  89. else if (god % 100 != 0 && god % 4 == 0)
  90. cout << "God vusokosnui!" << endl;
  91. else
  92. cout << "God ne vusokosnui!" << endl;
  93. }
  94. class MyExWithParamSecond :public exception {
  95.  
  96. };
  97.  
  98. void foo6(int god) {
  99. try {
  100. if (god < 0)
  101. throw MyExWithParamSecond();
  102.  
  103. }
  104. catch (MyExWithParamSecond e) {
  105. cout<<"Obrabotano klassom unasledovanum ot standartnogo klassa isklycheniy!"<<endl;
  106. cout<<e.what()<<endl;
  107. };
  108. if (god % 100 == 0 && god % 400 == 0)
  109. cout << "God vusokosnuy!" << endl;
  110. else if (god % 100 != 0 && god % 4 == 0)
  111. cout << "God vusokosnui!" << endl;
  112. else
  113. cout << "God ne vusokosnui!" << endl;
  114. }
  115.  
  116. void main() {
  117. foo1(-5);
  118. foo2(-5);
  119. foo3(-5);
  120. foo4(-5);
  121. foo5(-5);
  122. foo6(-5);
  123. system("pause");
  124. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement