What kind of exceptions are available in c++?
How to handle error in the destructor?
What is the output of this program?
1. #include2. #include 3. using namespace std; 4. void myunexpected () 5. { 6. cout << "unexpected called\n"; 7. throw 0; 8. } 9. void myfunction () throw (int) 10. { 11. throw 'x'; 12. } 13. int main () 14. { 15. set_unexpected (myunexpected); 16. try 17. { 18. myfunction(); 19. } 20. catch (int) 21. { 22. cout << "caught int\n"; 23. } 24. catch (...) 25. { 26. cout << "caught other exception\n"; 27. } 28. return 0; 29. }
What is the output of this program?
1. #include2. using namespace std; 3. int main() 4. { 5. int x = -1; 6. char *ptr; 7. ptr = new char[256]; 8. try 9. { 10. if (x < 0) 11. { 12. throw x; 13. } 14. if (ptr == NULL) 15. { 16. throw " ptr is NULL "; 17. } 18. } 19. catch (...) 20. { 21. cout << "Exception occurred: exiting "<< endl; 22. } 23. return 0; 24. }
What is the output of this program?
1. #include2. #include 3. using namespace std; 4. void myunexpected () 5. { 6. cout << "unexpected handler calledn"; 7. throw; 8. } 9. void myfunction () throw (int,bad_exception) 10. { 11. throw 'x'; 12. } 13. int main (void) 14. { 15. set_unexpected (myunexpected); 16. try 17. { 18. myfunction(); 19. } 20. catch (int) 21. { 22. cout << "caught int\n"; 23. } 24. catch (bad_exception be) 25. { 26. cout << "caught bad_exception\n"; 27. } 28. catch (...) 29. { 30. cout << "caught other exception \n"; 31. } 32. return 0; 33. }