What are the perdefined exceptions in c++?
Which of the following is best to include under try block?
What is the output of this program?
1. #include2. #include 3. using namespace std; 4. class Test 5. { 6. public: 7. Test(); 8. virtual ~Test(); 9. }; 10. int main() 11. { 12. Test *ptrvar = NULL; 13. try 14. { 15. cout << typeid(*ptrvar).name() << endl; 16. } 17. catch (bad_typeid) 18. { 19. cout << "The object is null" << endl; 20. } 21. return 0; 22. }
What is the output of this program?
1. #include2. #include 3. using namespace std; 4. class shape 5. { 6. public: 7. virtual void myvirtualfunc() const {} 8. }; 9. class mytriangle: public shape 10. { 11. public: 12. virtual void myvirtualfunc() const 13. { 14. }; 15. }; 16. int main() 17. { 18. shape shape_instance; 19. shape &ref_shape = shape_instance; 20. try 21. { 22. mytriangle &ref_mytriangle = dynamic_cast (ref_shape); 23. } 24. catch (bad_cast) 25. { 26. cout << "Caught: bad_cast exception\n"; 27. } 28. return 0; 29. }
What is the output of this program?
1. #include2. using namespace std; 3. int main() 4. { 5. char* ptr; 6. unsigned long int a = (size_t(0) / 3); 7. cout << a << endl; 8. try 9. { 10. ptr = new char[size_t(0) / 3]; 11. delete[ ] ptr; 12. } 13. catch(bad_alloc &thebadallocation) 14. { 15. cout << thebadallocation.what() << endl; 16. }; 17. return 0; 18. }