Interactive Quiz for Chapter 16

Question
Your Answer Result/Explanation
16.1
What is the output of the following code?
    #include  
    using namespace std;

    void f(int x) {
      if (x == 1)
        throw x;
    }

    int main()
    {
      try
      {
        f(1);
        cout << "B";
      }
      catch (int ex)
      {
        cout << "A";
      }
      cout << "C";

      return 0;
    }
                  
16.2
What is the output of the following code?
    #include  
    using namespace std;

    void f(int x) {
      if (x == 1)
        throw x;
    }

    int main()
    {
      try
      {
        f(2);
        cout << "B";
      }
      catch (int ex)
      {
        cout << "A";
      }
      cout << "C";

      return 0;
    }
                  
16.3
What is the output of the following code?
    #include  
    using namespace std;

    void f(int x) {
      if (x == 1)
        throw runtime_error("error");
    }

    int main()
    {
      try
      {
        f(1);
        cout << "B";
      }
      catch (runtime_error& ex)
      {
        cout << ex.what();
      }
      cout << "C";

      return 0;
    }
                  
16.4
What is the output of the following code?
    #include  
    using namespace std;

    void f(int x) {
      if (x == 1)
        throw runtime_error("error");
    }

    int main()
    {
      try
      {
        f(1);
        cout << "B";
      }
      catch (exception& ex)
      {
        cout << ex.what();
      }
      cout << "C";

      return 0;
    }