📜  C ++ |异常处理问题1

📅  最后修改于: 2021-06-28 19:39:51             🧑  作者: Mango

#include 
using namespace std;
int main()
{
   int x = -1;
   try {
      cout << "Inside try \n";
      if (x < 0)
      {
         throw x;
         cout << "After throw \n";
      }
   }
   catch (int x ) {
      cout << "Exception Caught \n";
   }
  
   cout << "After catch \n";
   return 0;
}

(一种)

Inside try
Exception Caught
After throw 
After catch

(B)

Inside try
Exception Caught
After catch

(C)

Inside try
Exception Caught

(D)

Inside try
After throw
After catch

答案: (B)
说明:引发异常时,不会执行throw语句之后的try块行。

当捕获到异常时,执行catch块之后的代码。捕获块通常写在末尾。
这个问题的测验

想要从精选的最佳视频中学习和练习问题,请查看《基础知识到高级C的C基础课程》。