Advertisement
avr39ripe

cppExceptionStackRollup

Aug 20th, 2021
1,380
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.04 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. void funcThree()
  4. {
  5.     std::cout << "funcThree Starts\n";
  6.     throw (float)36.6;
  7.     std::cout << "funcThree Ends\n";
  8. }
  9.  
  10. void funcTwo()
  11. {
  12.     std::cout << "funcTwo Starts\n";
  13.     try
  14.     {
  15.         funcThree();
  16.     }
  17.     catch (char ex)
  18.     {
  19.         std::cout << "funcTwo catches char exception\n";
  20.     }
  21.  
  22.     std::cout << "funcTwo Ends\n";
  23. }
  24.  
  25. void funcOne()
  26. {
  27.     std::cout << "funcOne Starts\n";
  28.     try
  29.     {
  30.         funcTwo();
  31.     }
  32.     catch (float ex)
  33.     {
  34.         std::cout << "funcOne catches float exception\n";
  35.     }
  36.     catch (bool ex)
  37.     {
  38.         std::cout << "funcOne catches bool exception\n";
  39.     }
  40.     catch (int ex)
  41.     {
  42.         std::cout << "funcOne catches int exception\n";
  43.     }
  44.  
  45.     std::cout << "funcOne Ends\n";
  46. }
  47.  
  48.  
  49. int main()
  50. {
  51.     std::cout << "Program starts\n";
  52.     try
  53.     {
  54.         funcOne();
  55.     }
  56.     catch (float ex)
  57.     {
  58.         std::cout << "main catches float exception\n";
  59.     }
  60.     catch (double ex)
  61.     {
  62.         std::cout << "main catches double exception\n";
  63.     }
  64.     catch (int ex)
  65.     {
  66.         std::cout << "main catches int exception\n";
  67.     }
  68.  
  69.     std::cout << "Program ends\n";
  70.  
  71.     return 0;
  72. }
  73.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement