Advertisement
avr39ripe

PV913ExceptionSteckRollup

Jul 29th, 2020
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.11 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. void funcThree()
  4. {
  5.     std::cout << "FuncThree Started!\n";
  6.  
  7.     //throw "Oops!";
  8.     //throw 'Z';
  9.     throw 42;
  10.  
  11.     std::cout << "FuncThree Ended!\n";
  12. }
  13.  
  14. void funcTwo()
  15. {
  16.     std::cout << "FuncTwo Started!\n";
  17.    
  18.     try
  19.     {
  20.         funcThree();
  21.     }
  22.    
  23.     catch (char ex)
  24.     {
  25.         std::cout << "FuncTwo catches CHAR exception!\n";
  26.     }
  27.  
  28.     std::cout << "FuncTwo Ended!\n";
  29. }
  30.  
  31.  
  32. void funcOne()
  33. {
  34.     std::cout << "FuncOne Started!\n";
  35.     try
  36.     {
  37.         funcTwo();
  38.     }
  39.    
  40.     catch (float ex)
  41.     {
  42.         std::cout << "FuncOne catches FLOAT exception!\n";
  43.     }
  44.  
  45.     catch (bool ex)
  46.     {
  47.         std::cout << "FuncOne catches BOOL exception!\n";
  48.     }
  49.  
  50.     catch (int ex)
  51.     {
  52.         std::cout << "FuncOne catches INT exception!\n";
  53.     }
  54.  
  55.     std::cout << "FuncOne Ended!\n";
  56. }
  57.  
  58. int main()
  59. {
  60.     std::cout << "Main Started!\n";
  61.    
  62.     try
  63.     {
  64.         funcOne();
  65.     }
  66.  
  67.     catch (int x)
  68.     {
  69.         std::cout << "MAIN catches INT exception!\n";
  70.     }
  71.  
  72.     catch (double x)
  73.     {
  74.         std::cout << "Double exception " << x << '\n';
  75.     }
  76.  
  77.     catch (float x)
  78.     {
  79.         std::cout << "float exception " << x << '\n';
  80.     }
  81.  
  82.     std::cout << "Main NORMALLY works again!\n";
  83.  
  84.     return 0;
  85. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement