When exceptions are used?
Pick out the correct Answer.
What is the output of this program?
1. #include2. using namespace std; 3. void PrintSequence(int StopNum) 4. { 5. int Num; 6. Num = 1; 7. while (true) 8. { 9. if (Num >= StopNum) 10. throw Num; 11. cout << Num << endl; 12. Num++; 13. } 14. } 15. int main(void) 16. { 17. try 18. { 19. PrintSequence(2); 20. } 21. catch(int ExNum) 22. { 23. cout << "exception: " << ExNum << endl; 24. } 25. return 0; 26. }
a) 1
b) exception: 2
c) 1
exception: 2
d) none of the mentioned
What is the output of this program?
1. #include2. using namespace std; 3. void test(int x) 4. { 5. try 6. { 7. if (x > 0) 8. throw x; 9. else 10. throw 'x'; 11. } 12. catch(int x) 13. { 14. cout<<"integer:"<
What is the output of this program?
1. #include2. using namespace std; 3. int main() 4. { 5. int a = 10, b = 20, c = 30; 6. float d; 7. try 8. { 9. if ((a - b) != 0) 10. { 11. d = c / (a - b); 12. cout << d; 13. } 14. else 15. { 16. throw(a - b); 17. } 18. } 19. catch (int i) 20. { 21. cout<<"Answer is infinite "<