📄 ex6_05.cpp
字号:
// Ex6_05.cpp
// Nested try blocks
#include <iostream>
using std::cin;
using std::cout;
using std::endl;
int main(void)
{
int height = 0;
const 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 << static_cast<double>(height)*inchesToMeters
<< " meters"
<< endl;
}
catch(const char aMessage[]) // start of catch block which
{ // catches exceptions of type
cout << aMessage << endl; // const char[]
}
cout << "Do you want to continue(y or n)?";
cin >> ch;
}
}
catch(int badHeight)
{
cout << badHeight << " inches is below minimum" << endl;
}
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -