Write throw clause inside catch handler - Exception Handling

Q.  Can we write throw clause inside catch handler?
- Published on 17 Jul 15

a. Yes
b. No

ANSWER: Yes
 

    Discussion

  • Digvijay   -Posted on 24 Oct 15
    Yes, we write throw clause inside catch handler.
    Example:
    void fun(int x)
    {
    try
    {
    if (x == 1)
    throw 10;
    }
    catch (int x)
    {
    cout << "\n In Integer catch block";
    throw 10;
    }
    catch (...)
    {
    cout << "\n\n in generic catch block";
    }
    }


    int main()
    {
    int b = 1;
    try
    {
    fun(b);
    }
    catch (char *e)
    {
    cout << e << endl;
    }
    catch (int x)
    {
    cout << "\n caught in int exception...\n\n";
    }
    return 0;
    }

Post your comment / Share knowledge


Enter the code shown above:

(Note: If you cannot read the numbers in the above image, reload the page to generate a new one.)