Home » C++ Programming » Exception Handling » Question
  1. What is the output of this program?
    #include <iostream>
    using namespace std;
    void Example(int num)
    {
    try
    {
    if (num > 0)
    throw num;
    else
    throw 'U';
    }
    catch(int num)
    {
    cout<<"Integer: "<< num << endl;
    }
    catch(char ch)
    {
    cout << "Character: " << ch;
    }
    }
    int main()
    {
    Example(12);
    Example(0);
    }
    1. Integer: 12
    2. Character: U
    3. Integer: 12
      Character: U
    4. Character: U
      Integer: 12
    5. None of these
Correct Option: C

We are passing the integer and character and catching it by using multiple catch statement.



Your comments will be displayed only after manual approval.