Which exception is thrown by dynamic_cast?
How do define the user-defined exceptions?
What is the output of this program?
1. #include2. #include 3. using namespace std; 4. struct MyException : public exception 5. { 6. const char * what () const throw () 7. { 8. return "C++ Exception"; 9. } 10. }; 11. int main() 12. { 13. try 14. { 15. throw MyException(); 16. } 17. catch(MyException& e) 18. { 19. cout << "Exception caught" << std::endl; 20. cout << e.what() << std::endl; 21. } 22. catch(std::exception& e) 23. { 24. } 25. }
What is the output of this program?
1. #include2. #include 3. using namespace std; 4. int main () 5. { 6. try 7. { 8. int* myarray = new int[1000]; 9. cout << "allocated"; 10. } 11. catch (exception& e) 12. { 13. cout << "Standard exception: " << e.what() << endl; 14. } 15. return 0; 16. }
What is the output of this program?
1. #include2. #include 3. using namespace std; 4. class myexception: public exception 5. { 6. virtual const char* what() const throw() 7. { 8. return "My exception"; 9. } 10. } myex; 11. int main () 12. { 13. try 14. { 15. throw myex; 16. } 17. catch (exception& e) 18. { 19. cout << e.what() << endl; 20. } 21. return 0; 22. }