Advertisement
Guest User

Untitled

a guest
Dec 13th, 2018
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.87 KB | None | 0 0
  1. #include <exception>
  2. #include <iostream>
  3.  
  4. class CMyException : public std::exception {
  5. public:
  6.     virtual char const* what() const {return "DIHT loves you \n";}
  7. };
  8.  
  9. class CMySuperException : public CMyException {
  10. public:
  11.     virtual char const* what() const {return "DIHT doesn't love you \n";}
  12. };
  13.  
  14. void f() {
  15.     throw CMyException();
  16. }
  17.  
  18. void g() {
  19.     throw CMySuperException();
  20. }
  21.  
  22. void h() {
  23.     try {
  24.         h();
  25.     } catch (CMySuperException& ) {
  26.         std::cout << "no problrm\n";
  27.     }
  28. }
  29.  
  30. int main() {
  31.     try {
  32.         f();
  33.     } catch (std::exception& e) {
  34.         std::cout << e.what();
  35.     } catch ( ... ) {
  36.         std::cout << "Abnormal exit\n";
  37.     }
  38.  
  39.     try {
  40.         h();
  41.     } catch (std::exception& e) {
  42.         std::cout << e.what();
  43.     } catch ( ... ) {
  44.         std::cout << "Abnormal exit\n";
  45.     }
  46.  
  47.     return 0;
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement