f1507.cpp
资源名称:c.rar [点击查看]
上传用户:puke2000
上传日期:2022-07-25
资源大小:912k
文件大小:2k
源码类别:

C#编程

开发平台:

Visual C++

  1. //=====================================
  2. // f1507.cpp
  3. // 异常捕捉网
  4. //=====================================
  5. #include<iostream>
  6. using namespace std;
  7. //-------------------------------------
  8. class HardwareErr{};  // 硬件故障错误
  9. class SizeErr{};       // 尺寸错误
  10. class PerformErr{};   // 性能不合要求
  11. class A{};              // 其他意外错误
  12. //-------------------------------------
  13. void metalPieseProccess(int);          // 金属片加工
  14. void metalGroupProccess(int);          // 逐组加工稀有金属
  15. void calcVSize();                         // 计算纵向尺寸
  16. void hProccess();                         // 横向加工
  17. void vProccess();                         // 纵向加工
  18. void performTest();                       // 性能测试
  19. bool tooSmallHSize(){ return false; } // 横向尺寸太小
  20. bool performTestFail(){ return true; }// 性能测试失败
  21. bool tooSmallVSize(){ return false; }  // 纵向尺寸太小
  22. //-------------------------------------
  23. int main(){                                // 稀有金属处理
  24.   try{
  25.     for(int i=0; i<10; ++i) metalGroupProccess(i);
  26.   }catch(HardwareErr){
  27.     cout<<"HardwareError.n";
  28.     // 机器复位,停机
  29.   }catch(PerformErr){
  30.     cout<<"PerformError Stop.n";
  31.     //机器复位,停机
  32.   }catch(...){                            // 其他任何故障
  33.     cout<<"Any Kind Of Error.n";     // 其他机器硬件故障
  34.     // 停机
  35.   }
  36. }//------------------------------------
  37. void metalGroupProccess(int){
  38.   try{
  39.     for(int i=0; i<10; ++i) metalPieseProccess(i);
  40.   }catch(SizeErr){
  41.     cout<<"SizeError.n";
  42.     // 片加工尺寸故障...报废本组金属
  43.   }catch(PerformErr){
  44.     cout<<"PerformErr.n";
  45.     // 性能测试失败善后处理...加工件离机
  46.     throw;
  47.   }
  48. }//------------------------------------
  49. void metalPieseProccess(int){
  50.   hProccess();
  51.   performTest();
  52.   try{
  53.     vProccess();
  54.     // metalPieseProccess
  55.   }catch(SizeErr){
  56.     cout<<"VSizeErrReport.n";
  57.     // 纵向尺寸错误...报废本片金属
  58.   }
  59. }//------------------------------------
  60. void calcVSize(){
  61.   int a;
  62.   if(tooSmallVSize()) throw SizeErr();
  63.   if(a) throw A();
  64.   // ...
  65. }//------------------------------------
  66. void vProccess(){
  67.   calcVSize();
  68.   //...
  69. }//------------------------------------
  70. void hProccess(){
  71.   if(tooSmallHSize()) throw SizeErr();
  72.   //...
  73. }//------------------------------------
  74. void performTest(){
  75.   if(performTestFail()) throw PerformErr();
  76.   //...
  77. }//====================================
  78.