⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ex6_05.cpp

📁 Beginning Visual C++ 6源码。Wrox。
💻 CPP
字号:
// EX6_05.cpp
// Nested try blocks
#include <iostream>
using namespace std;

int main(void)
{
   int Height = 0;
   double InchesToMeters = 0.0254;
   char ch = 'y';

   try                       // Outer try block
   {
      while(ch == 'y'||ch =='Y')
      {
         cout << "Enter a height in inches: "; 
         cin >> Height;        // Read the height to be converted

         try                   // Defines try block in which
         {                     // exceptions may be thrown
            if(Height > 100)
               throw "Height exceeds maximum";   // Exception thrown
            if(Height < 9)
               throw Height;                     // Exception thrown

               cout << (double)Height*InchesToMeters 
                    << " meters" << endl;

               cout << "Do you want to continue(y or n)?";
               cin >> ch;
         }

         catch(char* aMessage)      // start of catch block which
         {                          // catches exceptions of type char*
            cout << aMessage << endl;
         }
      }
   }
   catch(int BadHeight)
   {
      cout << BadHeight << " inches is below minimum" << endl;
   }
   return 0;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -